home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / hotkeyEditor.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  83.7 KB  |  3,155 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // $Source: /vobs/aw/Maya/src/Maya/Maya/scripts/hotkeyEditor.mel $
  19. //
  20. // $Locker:  $
  21. //
  22. // $Author: kpicott $
  23. // $Revision: /main/62 $
  24. // $Date: 2000/05/16 12:30:32 $
  25. //
  26. //  Description:
  27. //    This contains procedures necessary for
  28. //    the Hotkey/NameCommand editor.
  29. //
  30.  
  31. /*
  32. //
  33. //    These are the local and global procedures defined in this file.  As well
  34. //    as the unique names of the UI objects created.
  35. //
  36. // ----------------------------------------------------------------------
  37. //
  38.  
  39. //    Local procedures.
  40. //
  41. string constructHotkeyCommand(string $key, int $ctrl,
  42.     int $alt, int $press, string $command)
  43.  
  44. int isValidKey(string $name)
  45. int isValidName(string $name)
  46. int isUniqueName(string $name)
  47. int isValidCategory(string $name)
  48. int isExistingCategory(string $name)
  49. string getCurrentCategory()
  50. string getCurrentRunTimeCommand()
  51. int getNameCommand(string $nameCommand)
  52. string [] getAllHotkeys(string $command)
  53.  
  54. updateCommandInfo()
  55. updateCommandButtons()
  56. updateRemoveHotkeyButton()
  57. updateCurrentHotkeys()
  58. enableNewHotkeyArea(int $enable);
  59. setQueryHotkeyText(string $label)
  60. int updateQueryHotkeyText()
  61. updateCommandTextScrollList(string $command)
  62. updateCategoryPopupMenu()
  63. updateKeyPopupMenu()
  64.  
  65. removeHotkey(string $hotkey)
  66. deleteRunTimeCommand(string $command)
  67.  
  68. createCommandListArea()
  69. createCommandInfoArea()
  70. createCurrentHotkeyArea()
  71. createNewHotkeyArea()
  72. createButtonsArea()
  73.  
  74. resetCreateOrEditMode()
  75.  
  76. //    Global procedures.
  77. //
  78. string[] getAllValidKeys()
  79. string getHotkeyCommand(string $key, int $ctrl,
  80.     int $alt, int $press)
  81. string getRunTimeCommandFromNameCommand(string $nameCommand)
  82.  
  83. hotkeyEditorCategoryTextScrollListSelect()
  84. hotkeyEditorCommandTextScrollListSelect()
  85.  
  86. hotkeyEditorHotkeyKeyFieldChange()
  87. hotkeyEditorHotkeyCtrlCheckBoxChange()
  88. hotkeyEditorHotkeyAltCheckBoxChange()
  89. hotkeyEditorHotkeyPressRadioButtonChange()
  90. hotkeyEditorHotkeyReleaseRadioButtonChange()
  91. hotkeyEditorHotkeyTextScrollListSelect()
  92.  
  93. hotkeyEditorCategoryPopupMenuSelect(string $category)
  94. hotkeyEditorKeyPopupMenuSelect(string $key)
  95.  
  96. hotkeyEditorCreateCommand()
  97. hotkeyEditorEditCommand()
  98. hotkeyEditorDeleteCommand()
  99. hotkeyEditorAcceptCommand()
  100. hotkeyEditorCancelCommand()
  101. hotkeyEditorSearchForRunTimeCommand()
  102.  
  103. hotkeyEditorAssignHotkey()
  104. hotkeyEditorQueryHotkey()
  105. hotkeyEditorFindHotkey()
  106. hotkeyEditorRemoveHotkey()
  107. hotkeyEditorRestoreDefaultHotkeys()
  108. hotkeyEditorListAllHotkeys()
  109.  
  110. hotkeyEditorSave()
  111. hotkeyEditorClose()
  112.  
  113. hotkeyEditor()
  114.  
  115. //    Interface for Marking Menu Editor - These procedures
  116. //    should not be called from anywhere else.
  117. //
  118. string hotkeyEditor_generatePressAnnotationForMM(string)
  119. string hotkeyEditor_generateReleaseAnnotationForMM(string)
  120. int hotkeyEditor_createMarkingMenu(string, string, string) 
  121. hotkeyEditor_deleteMarkingMenu(string)
  122. int hotkeyEditor_renameMarkingMenu(string, string, string, string)
  123. int hotkeyEditor_doesMarkingMenuExist(string)
  124.  
  125. global int $gHotkeyEditorInCreateMode;
  126. global int $gHotkeyEditorInEditMode;
  127.  
  128. //    Names of UI objects.
  129. //
  130. HotkeyEditor
  131.  
  132. HotkeyEditorCategoryTextScrollList
  133. HotkeyEditorCommandTextScrollList
  134.  
  135. HotkeyEditorNameField
  136. HotkeyEditorDescriptionField
  137. HotkeyEditorCategoryField
  138. HotkeyEditorCategoryPopupMenuButton
  139. HotkeyEditorCategoryPopupMenu
  140. HotkeyEditorCommandField
  141.  
  142. HotkeyEditorCreateCommandButton
  143. HotkeyEditorEditCommandButton
  144. HotkeyEditorDeleteCommandButton
  145. HotkeyEditorAcceptCommandButton
  146. HotkeyEditorCancelCommandButton
  147. HotkeyEditorSearchButton
  148.  
  149. HotkeyEditorHotkeyTextScrollList
  150. HotkeyEditorRemoveHotkeyButton
  151. HotkeyEditorRestoreDefaultHotkeysButton
  152. HotkeyEditorListAllHotkeysButton
  153.  
  154. HotkeyEditorKeyLabel
  155. HotkeyEditorKeyField
  156. HotkeyEditorKeyPopupMenuButton
  157. HotkeyEditorKeyPopupMenu
  158. HotkeyEditorModifierLabel
  159. HotkeyEditorCtrlCheckBox
  160. HotkeyEditorAltCheckBox
  161. HotkeyEditorDirectionLabel
  162. HotkeyEditorPressRadioButton
  163. HotkeyEditorReleaseRadioButton
  164. HotkeyEditorRepeatableLabel
  165. HotkeyEditorRepeatableCheckBox
  166. HotkeyEditorAssignHotkeyButton
  167. HotkeyEditorQueryHotkeyButton
  168. HotkeyEditorFindHotkeyButton
  169. HotkeyEditorQueryResultText
  170.  
  171. HotkeyEditorSaveButton
  172. HotkeyEditorCloseButton
  173. */
  174.  
  175.  
  176. proc string constructHotkeyCommand(
  177.     string $key,
  178.     int    $ctrl,
  179.     int    $alt,
  180.     int        $cmd,
  181.     int    $press,
  182.     int    $repeat,
  183.     string $command)
  184. //
  185. //    Description:
  186. //        Construct and return a string containing a valid hotkey command
  187. //        that can be passed to the eval() funtion.
  188. //
  189. //    Arguments:
  190. //        key        - The key string.
  191. //        ctrl    - True if Ctrl modifer is required, false otherwise.
  192. //        alt        - True if Alt modifer is required, false otherwise.
  193. //        press    - True for key press, false for key release.
  194. //        repeat    - True if the hotkey is repeatable, false otherwise.
  195. //        command    - The command string to execute.
  196. //
  197. {
  198.     //    Must surround the key string in double quote characters.
  199.     //
  200.     string $result = ("hotkey -k \"");
  201.  
  202.     //    Must preceed back slashes and double quote characters with
  203.     //    a backslash.
  204.     //
  205.     if ("\\" == $key || "\"" == $key) $key = "\\" + $key;
  206.     
  207.     $result += ($key + "\" ");
  208.  
  209.     if ($ctrl) $result += "-ctl ";
  210.     if ($alt) $result += "-alt ";
  211.     if ($cmd) $result += "-cmd";
  212.  
  213.     if ($press) $result += "-name \"";
  214.     else $result += "-releaseName \"";
  215.  
  216.     $result += ($command + "\" ");
  217.  
  218.     if ($press) $result += "-pressCommandRepeat ";
  219.     else $result += "-releaseCommandRepeat ";
  220.  
  221.     $result += $repeat;
  222.     
  223.     return $result;
  224. }
  225.  
  226. proc int isValidKey(string $name)
  227. //
  228. //    Description:
  229. //        Return true if the given string corresponds to a valid key
  230. //        that a hotkey can be assigned to.
  231. //
  232. //        See the getAllValidKeys() procedure for a list of all the
  233. //        valid keys.  For example, "a", "Page_Down", and "\\" are all
  234. //        valid keys.  However, "Foo", " ", and "f1" (must be uppercase) 
  235. //        are not.
  236. //        
  237. {
  238.     int $result = false;
  239.     string $keys[] = getAllValidKeys();
  240.     
  241.     for ($key in $keys) {
  242.         if ($name == $key) {
  243.             $result = true;
  244.             break;
  245.         }
  246.     }
  247.  
  248.     return $result;
  249. }
  250.  
  251. proc int isValidName(string $name)
  252. //
  253. //    Description:
  254. //        Determine if the given string is potentially a valid name.
  255. //        Note that this procedure does not test to see if the name is
  256. //        unique, it just tests the string characters.
  257. //
  258. //        Check to ensure that the string does not begin with a number
  259. //        and is followed only by alphanumeric characters or underscores.
  260. //
  261. {
  262.     int $result = false;
  263.  
  264.     if ("" != $name) {
  265.         //
  266.         //    Begins with letter or underscore, followed by
  267.         //    letters, digits, or underscores.
  268.         //
  269.         string $regExpr = "([a-zA-Z_]+)([[a-zA-Z0-9_])*";
  270.         string $temp = match($regExpr, $name);
  271.         if ($temp == $name) {
  272.             $result = true;
  273.         }
  274.     }
  275.  
  276.     return $result;
  277. }
  278.  
  279. proc int isUniqueName(string $name)
  280. //
  281. //    Description:
  282. //        Determine if the given string is a unique name.
  283. //
  284. //        Compare it with existing commands, scripts, and procedures.
  285. //
  286. {    
  287.     int $result = false;
  288.  
  289.     if ("Unknown" == `whatIs $name`) {
  290.         $result = true;
  291.     }
  292.  
  293.     return $result;
  294. }
  295.  
  296. proc int isValidCategory(string $category)
  297. //
  298. //    Description:
  299. //        Determine if the given string is potentially a valid category.
  300. //
  301. //        Check to ensure that the string does not begin with a number
  302. //        and is followed only by alphanumeric characters, underscores,
  303. //        or spaces.
  304. //
  305. {
  306.     int $result = false;
  307.  
  308.     if ("" != $category) {
  309.         //
  310.         //    Begins with letter or underscore, followed by
  311.         //    letters, digits, spaces, or underscores.
  312.         //
  313.         string $regExpr = "([a-zA-Z_]+)([[a-zA-Z0-9_ ])*";
  314.         string $temp = match($regExpr, $category);
  315.         if ($temp == $category) {
  316.             $result = true;
  317.         }
  318.     }
  319.  
  320.     return $result;
  321. }
  322.  
  323. proc int isExistingCategory(string $name)
  324. //
  325. //    Description:
  326. //        Determine if the given category already exists.
  327. //
  328. {
  329.     int $result = false;
  330.  
  331.     string $categories[] = `textScrollList -query -allItems 
  332.         HotkeyEditorCategoryTextScrollList`;
  333.     int $index, $numberOfCategories = size($categories);
  334.  
  335.     for ($index = 0; $index < $numberOfCategories; $index++) {
  336.         if ($name == $categories[$index]) {
  337.             $result = true;
  338.             break;
  339.         }
  340.     }    
  341.  
  342.     return $result;
  343. }
  344.  
  345. proc string getNameErrorMessage(string $name)
  346. //
  347. //    Description:
  348. //        Construct an appropriate error message for the given name.
  349. //
  350. //        The error message will take into consideration whether
  351. //        the name already refers to a command, script or procedure.
  352. //
  353. //        An empty string is returned if the name is unique.
  354. //
  355. {
  356.     string $result = "";
  357.  
  358.     string $whatIsResult = `whatIs $name`;
  359.     string $buffer[];
  360.     int $tokenCount = `tokenize $whatIsResult $buffer`;
  361.  
  362.     switch ($tokenCount) {
  363.         case 1:
  364.             if ("Unknown" == $buffer[0]) {
  365.                 $result = "";
  366.  
  367.             } else if ("Command" == $buffer[0]) {
  368.                 $result = "A command with the name " + $name
  369.                     + " already exists.\nPlease enter another name.";
  370.             } else {
  371.                 $result = "The name " + $name
  372.                     + " is not unique.\nPlease enter another name.";
  373.             }
  374.             break;
  375.  
  376.         case 4:
  377.             $result = "A script with the name " + $name
  378.                 + " already exists in\n" + $buffer[3] 
  379.                 + ".\nPlease enter another name.";
  380.             break;
  381.  
  382.         case 5:
  383.             $result = "A MEL procedure with the name " + $name
  384.                 + " already exists in\n" + $buffer[4] 
  385.                 + ".\nPlease enter another name.";
  386.             break;
  387.  
  388.         default:
  389.             $result = "The name " + $name
  390.                 + " is not unique.\nPlease enter another name.";
  391.             break;
  392.     }
  393.  
  394.     return $result;
  395. }
  396.  
  397. proc string getCurrentCategory()
  398. //
  399. //    Description:
  400. //        Determine the current category of commands being displayed in the
  401. //        Hotkey Editor.
  402. //
  403. {
  404.     string $result = "", $category[];
  405.  
  406.     $category = `textScrollList -query -selectItem HotkeyEditorCategoryTextScrollList`;
  407.  
  408.     if (size($category) > 0 && "Uncategorized" != $category[0]) {
  409.         $result = $category[0];
  410.     }
  411.  
  412.     return $result;
  413. }
  414.  
  415. proc string getCurrentRunTimeCommand()
  416. //
  417. //    Description:
  418. //        Determine the runTimeCommand currently selected by the user.
  419. //
  420. //    Returns:
  421. //        A string containing the name of the current selected 
  422. //        runTimeCommand.  If no command is selected then an empty 
  423. //        string is returned.
  424. //
  425. {
  426.     string $result = "", $command[];
  427.  
  428.     $command = `textScrollList -query -selectItem HotkeyEditorCommandTextScrollList`;
  429.  
  430.     if (size($command) > 0) {
  431.         $result = $command[0];
  432.     }
  433.  
  434.     return $result;
  435. }
  436.  
  437. proc int getNameCommand(string $nameCommand)
  438. //
  439. //    Description:
  440. //        Determine if a nameCommand with the given name exists.
  441. //
  442. //    Arguments:
  443. //        nameCommand    - The $nameCommand.
  444. //
  445. //    Returns:
  446. //        If the nameCommand exists then a 1 based index is returned.
  447. //        This index can then be used for querying with the 'assignCommand'
  448. //        command.
  449. //
  450. //        If the nameCommand does not exist then 0 is returned.
  451. //
  452. {
  453.     int $result = 0, $index;
  454.     int $numberOfNameCommands = `assignCommand -query -numElements`;
  455.  
  456.     for ($index = 1; $index <= $numberOfNameCommands; $index++) {
  457.         if ($nameCommand == `assignCommand -query -name $index`) {
  458.             $result = $index;
  459.             break;
  460.         }
  461.     }
  462.  
  463.     return $result;
  464. }
  465.  
  466. proc string [] getAllHotkeys(string $command)
  467. //
  468. //    Description:
  469. //        Determine all the hotkeys that will invoke the specified
  470. //        runTimeCommand.
  471. //
  472. //    Returns:
  473. //        A string array containing all the hotkeys attahed to the
  474. //        specified command.  Each string element in the array will
  475. //        full describe the hotkey, for example: "Ctrl b", or "Alt Space",
  476. //        or "N Release".
  477. //
  478. {
  479.     string $result[], $keyInfo[], $hotkey, $cmd;
  480.     int $resultIndex = 0, $index, $numberOfNameCommands;
  481.     int $hotkeyInfoIndex, $numberOfHotkeys;
  482.  
  483.     if ("" != $command) {
  484.         $numberOfNameCommands = `assignCommand -query -numElements`;
  485.         for ($index = 1; $index <= $numberOfNameCommands; $index++) {
  486.             $cmd = `assignCommand -query -command $index`;
  487.             //
  488.             //    Is this nameCommand pointing to the target runTimeCommand?
  489.             //
  490.             if ($cmd == $command) {
  491.                 //
  492.                 //    For this nameCommand determine all the hotkeys
  493.                 //    that point to it.
  494.                 //
  495.                 $keyInfo = AWAppendStringsToStringArray(
  496.                     `assignCommand -query -keyArray $index`, $keyInfo);
  497.  
  498.                 //    Don't stop searching.  There may be other nameCommand
  499.                 //    objects that point to the specified runTimeCommand.
  500.             }
  501.         }
  502.     }
  503.  
  504.     //    The keyInfo array should now contain all the hotkeys that
  505.     //    point to the target runTimeCommand.
  506.     //
  507.     $hotkeyInfoIndex = 0;
  508.     $numberOfHotkeys = size($keyInfo) / 5;
  509.     for ($index = 0; $index < $numberOfHotkeys; $index++) {
  510.         $hotkey = "";
  511.         if ("1" == $keyInfo[$hotkeyInfoIndex + 2]) {
  512.             if (`about -mac`) {
  513.                 $hotkey += ("control+");
  514.             }
  515.             else {
  516.                 $hotkey += ("Ctrl+");
  517.             }
  518.         }
  519.         if ("1" == $keyInfo[$hotkeyInfoIndex + 1]) {
  520.             if (`about -mac`) {
  521.                 $hotkey += ("option+");
  522.             }
  523.             else {
  524.                 $hotkey += ("Alt+");
  525.             }
  526.         }
  527.  
  528.         if ("1" == $keyInfo[$hotkeyInfoIndex + 4]) {
  529.             $hotkey += ("command+");
  530.         }
  531.  
  532.         if (" " == $keyInfo[$hotkeyInfoIndex]) {
  533.             if (`about -mac`) {
  534.                 $hotkey += ("space");
  535.             }
  536.             else {
  537.                 $hotkey += ("Space");
  538.             }
  539.         } else {
  540.             $hotkey += $keyInfo[$hotkeyInfoIndex];
  541.         }
  542.  
  543.         if ("1" == $keyInfo[$hotkeyInfoIndex + 3]) {
  544.             $hotkey += " Release";
  545.         }
  546.  
  547. // Command keys needs to be taken care of. So an extra field in the array. - Vidya.
  548.  
  549.         $hotkeyInfoIndex += 5;
  550.  
  551.         $result[$resultIndex++] = $hotkey;
  552.     }
  553.  
  554.     return $result;
  555. }
  556.  
  557. proc updateCommandInfo()
  558. //
  559. //    Description:
  560. //        Update the UI that displays information on the current
  561. //        selected runTimeCommand.
  562. //
  563. //        This procedure should be called whenever the current selected
  564. //        runTimeCommand is changed.
  565. //
  566. {
  567.     global int $gHotkeyEditorInCreateMode;
  568.     global int $gHotkeyEditorInEditMode;
  569.  
  570.     string $name, $description, $command, $category, $focus;
  571.     int $nameEditable = false, $descriptionEditable = false;
  572.     int $commandEditable = false, $categoryEditable = false;
  573.  
  574.     //    Get the current selected runTimeCommand and category.
  575.     //
  576.     $name = getCurrentRunTimeCommand();
  577.     $category = getCurrentCategory();
  578.  
  579.     if ("" != $name) {
  580.         //
  581.         //    Get the runTimeCommand's description and command.
  582.         //
  583.         $description = `runTimeCommand -query -annotation $name`;
  584.         $command = `runTimeCommand -query -command $name`;
  585.     }
  586.  
  587.     if ($gHotkeyEditorInCreateMode) {
  588.         //
  589.         //    In Create mode, ie. the user pressed the "Create" button.
  590.         //
  591.         //    In this mode clear out the name, description, and command
  592.         //    fields so the user can type in new values.
  593.         //
  594.         //    Don't clear out the category field, it's most likely the
  595.         //    user will want to add the command to the current category.
  596.         //
  597.         $name = "";
  598.         $description = "";
  599.         $command = "";
  600.  
  601.         //    Be sure to enable all the fields for editing.
  602.         //
  603.         $nameEditable = true;
  604.         $descriptionEditable = true;
  605.         $categoryEditable = true;
  606.         $commandEditable = true;
  607.  
  608.         //    Send keyboard focus to the name field.
  609.         //
  610.         $focus = "HotkeyEditorNameField";
  611.         
  612.     } else if ($gHotkeyEditorInEditMode) {
  613.         //
  614.         //    In Edit mode, ie. the user pressed the "Edit" button.
  615.         //
  616.         //    Don't clear out any of the fields, but do make them all
  617.         //    editable.
  618.         //
  619.         $nameEditable = true;
  620.         $descriptionEditable = true;
  621.         $categoryEditable = true;
  622.         $commandEditable = true;
  623.  
  624.         //    Send keyboard focus to the name field.
  625.         //
  626.         $focus = "HotkeyEditorNameField";
  627.  
  628.     } else {
  629.         //
  630.         //    No mode.
  631.         //
  632.     }
  633.  
  634.     //    Update the controls.
  635.     //
  636.     textField -edit -text $name -editable $nameEditable
  637.         HotkeyEditorNameField;
  638.     textField -edit -text $description -insertionPosition 1
  639.         -editable $descriptionEditable
  640.         HotkeyEditorDescriptionField;
  641.     textField -edit -text $category
  642.         -editable $categoryEditable
  643.         HotkeyEditorCategoryField;
  644.     iconTextButton -edit
  645.         -enable $categoryEditable
  646.         HotkeyEditorCategoryPopupMenuButton;
  647.     scrollField -edit -text $command -insertionPosition 1 
  648.         -editable $commandEditable
  649.         HotkeyEditorCommandField;
  650.  
  651.     if(`about -mac`){
  652.       scrollField -edit -editable $commandEditable HotkeyEditorCommandField;
  653.     }
  654.  
  655.  
  656.  
  657.     //    Set keyboard focus.
  658.     //
  659.     if ("" != $focus) {
  660.         setFocus $focus;
  661.     }
  662. }
  663.  
  664. proc updateCommandButtons()
  665. //
  666. //    Description:
  667. //        Update the command buttons.
  668. //
  669. //        This procedure should be called whenever the current selected
  670. //        runTimeCommand is changed, or when the mode of the command 
  671. //        area changes.
  672. //
  673. {
  674.     global int $gHotkeyEditorInCreateMode;
  675.     global int $gHotkeyEditorInEditMode;
  676.  
  677.     int $enableCreate = false, $enableEdit = false;
  678.     int $enableDelete = false, $enableSearch = false;
  679.     int $enableAccept = false, $enableCancel = false;
  680.  
  681.     string $key = `textField -query -text HotkeyEditorKeyField`;
  682.     string $command = getCurrentRunTimeCommand();
  683.     string $hotkeys[];
  684.  
  685.     //    Should the Create Command button be enabled?
  686.     //
  687.     //    It should always be enabled except for when the user presses
  688.     //    it or the Edit Command button.  When that happens the button
  689.     //    should be disabled until the user presses either the 
  690.     //    Accept or Cancel button.
  691.     //
  692.     if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode) {
  693.         $enableCreate = true;
  694.     }
  695.  
  696.     //    Should the Edit Command button be enabled?
  697.     //
  698.     //    It should be enabled if the selected command is not a default
  699.     //    one and if the user has not already pressed the Edit or Create
  700.     //    Command button.
  701.     //
  702.     if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode &&
  703.         "" != $command && !`runTimeCommand -query -default $command`) {
  704.         $enableEdit = true;
  705.     }
  706.  
  707.     //    Should the Delete command button be enabled?
  708.     //
  709.     //    It should be enabled if the selected command is not a default
  710.     //    one and if the user has not already pressed the Edit or Create
  711.     //    Command button.
  712.     //
  713.     if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode &&
  714.         "" != $command && !`runTimeCommand -query -default $command`) {
  715.         $enableDelete = true;
  716.     }
  717.  
  718.     //    Should the Accept Command button be enabled?
  719.     //
  720.     //    If the editor is in Create or Edit command mode then yes it should.
  721.     //
  722.     if ($gHotkeyEditorInCreateMode || $gHotkeyEditorInEditMode) {
  723.         $enableAccept = true;
  724.     }
  725.  
  726.     //    Should the Cancel Command button be enabled?
  727.     //
  728.     //    If the editor is in Create or Edit command mode then yes it should.
  729.     //
  730.     if ($gHotkeyEditorInCreateMode || $gHotkeyEditorInEditMode) {
  731.         $enableCancel = true;
  732.     }
  733.  
  734.     //    Should the Search button be enabled?
  735.     //
  736.     //    It should always be enabled except for when the user presses
  737.     //    it or the Edit Command button.  
  738.     //
  739.     if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode) {
  740.         $enableSearch = true;
  741.     }
  742.  
  743.     button -edit -enable $enableCreate HotkeyEditorCreateCommandButton;
  744.     button -edit -enable $enableEdit HotkeyEditorEditCommandButton;
  745.     button -edit -enable $enableDelete HotkeyEditorDeleteCommandButton;
  746.     button -edit -enable $enableAccept HotkeyEditorAcceptCommandButton;
  747.     button -edit -enable $enableCancel HotkeyEditorCancelCommandButton;
  748.     button -edit -enable $enableSearch HotkeyEditorSearchButton;
  749. }
  750.  
  751. proc updateRemoveHotkeyButton()
  752. //
  753. //    Description:
  754. //        Update the remove hotkey button.
  755. //
  756. //        This procedure should be called whenever the current hotkey
  757. //        selection changes.
  758. //
  759. {
  760.     int $enableRemove = false;
  761.  
  762.     //    Should the Remove Hotkey button be enabled?
  763.     //
  764.     //    If there is a Hotkey selected in the Current Hotkeys list then
  765.     //    yes it should.
  766.     //
  767.     $hotkeys = `textScrollList -query -selectItem 
  768.         HotkeyEditorHotkeyTextScrollList`;
  769.     
  770.     if (size($hotkeys) > 0) {
  771.         $enableRemove = true;
  772.     }
  773.  
  774.     button -edit -enable $enableRemove HotkeyEditorRemoveHotkeyButton;
  775. }
  776.  
  777. proc updateCurrentHotkeys()
  778. //
  779. //    Description:
  780. //        Update the area that informs the user what hotkeys are currently
  781. //        assigned to the selected runTimeCommand.
  782. //
  783. {
  784.     string $runTimeCommand = getCurrentRunTimeCommand();
  785.     string $hotkey, $hotkeys[];
  786.     textScrollList -edit -removeAll HotkeyEditorHotkeyTextScrollList;
  787.  
  788.     //    Search through all nameCommands for the ones that point
  789.     //    to the runTimeCommand argument.
  790.     //
  791.     $hotkeys = getAllHotkeys($runTimeCommand);
  792.  
  793.     for ($hotkey in $hotkeys) {
  794.         textScrollList -edit -append $hotkey HotkeyEditorHotkeyTextScrollList;
  795.     }
  796.     
  797.     updateRemoveHotkeyButton();
  798. }
  799.  
  800. proc enableNewHotkeyArea(int $enable)
  801. //
  802. //    Description:
  803. //        Update the enable state of the new hotkey assignment UI.
  804. //
  805. {
  806.     text -edit -enable $enable HotkeyEditorKeyLabel;
  807.     textField -edit -enable $enable HotkeyEditorKeyField;
  808.     iconTextButton -edit -enable $enable HotkeyEditorKeyPopupMenuButton;
  809.     text -edit -enable $enable HotkeyEditorModifierLabel;
  810.     checkBox -edit -enable $enable HotkeyEditorCtrlCheckBox;
  811.     checkBox -edit -enable $enable HotkeyEditorAltCheckBox;
  812.     if(`about -macOS`){
  813.         checkBox -edit -enable $enable HotkeyEditorCmdCheckBox;
  814.     }
  815.     text -edit -enable $enable HotkeyEditorDirectionLabel;
  816.     radioButton -edit -enable $enable HotkeyEditorPressRadioButton;
  817.     radioButton -edit -enable $enable HotkeyEditorReleaseRadioButton;
  818.     text -edit -enable $enable HotkeyEditorRepeatableLabel;
  819.     checkBox -edit -enable $enable HotkeyEditorRepeatableCheckBox;
  820.     button -edit -enable $enable HotkeyEditorAssignHotkeyButton;
  821.     button -edit -enable $enable HotkeyEditorQueryHotkeyButton;
  822.     button -edit -enable $enable HotkeyEditorFindHotkeyButton;
  823. }
  824.  
  825. proc setQueryHotkeyText(string $label)
  826. //
  827. //    Description:
  828. //        Set the query text message.
  829. //
  830. {
  831.     text -edit -label $label HotkeyEditorQueryResultText;
  832. }
  833.  
  834. proc int updateQueryHotkeyText()
  835. //
  836. //    Description:
  837. //        Update the text that displays the current hotkey mapping.
  838. //
  839. //    Returns:
  840. //        True if the query was successful, false otherwise.  A
  841. //        query may be unsuccessful if the user enters an invalid
  842. //        value in the key field.
  843. //
  844. {
  845.     int $result = false, $cmd=0;
  846.  
  847.     string $label = "\"";
  848.     string $key = `textField -query -text HotkeyEditorKeyField`;
  849.     int $ctrl = `checkBox -query -value HotkeyEditorCtrlCheckBox`;
  850.     int $alt = `checkBox -query -value HotkeyEditorAltCheckBox`;
  851.     int $press = `radioButton -query -select HotkeyEditorPressRadioButton`;
  852.     if(`about -macOS`){
  853.         $cmd = `checkBox -query -value HotkeyEditorCmdCheckBox`;
  854.     }
  855.  
  856.     if ("" == $key || !isValidKey($key)) {
  857.         $result = false;
  858.  
  859.     } else {
  860.         $result = true;
  861.  
  862.         if ($ctrl) {
  863.             if (`about -mac`) {
  864.                 $label += ("control+");
  865.             }
  866.             else {
  867.                 $label += ("Ctrl+");
  868.             }
  869.         }
  870.         if ($alt) {
  871.             if (`about -mac`) {
  872.                 $label += ("option+");
  873.             }
  874.             else {
  875.                 $label += ("Alt+");
  876.             }
  877.         }
  878.         if($cmd){
  879.             $label += ("command+");
  880.         }
  881.  
  882.         $label += $key;
  883.  
  884.         if (!$press) {
  885.             $label += " Release";
  886.         }
  887.  
  888.         $label += "\" is assigned to:\n  ";
  889.  
  890.         string $command = getHotkeyCommand($key, $ctrl, $alt, $cmd, $press);
  891.  
  892.         if ("" == $command) {
  893.             $label += "Nothing";
  894.         } else {
  895.             $label += $command;
  896.         }
  897.  
  898.         setQueryHotkeyText($label);
  899.     }
  900.  
  901.     return $result;
  902. }
  903.  
  904. proc updateCommandTextScrollList(string $command)
  905. //
  906. //    Description:
  907. //        Fill in the command list with all the commands that belong to
  908. //        the current selected category.
  909. //
  910. //        If a command argument is passed in then make sure that command 
  911. //        is selected and visible in the list.
  912. //
  913. {
  914.     string $list = "HotkeyEditorCommandTextScrollList";
  915.     string $selectedCategory[], $category, $runTimeCommands[];
  916.     int $index, $numberOfItems, $numberOfLines, $showItem;
  917.  
  918.     waitCursor -state on;
  919.  
  920.     $selectedCategory = `textScrollList -query 
  921.         -selectItem HotkeyEditorCategoryTextScrollList`;
  922.  
  923.     if (1 == size($selectedCategory)) {
  924.         if ("Uncategorized" == $selectedCategory[0]) {
  925.             $selectedCategory[0] = "";            
  926.         }
  927.  
  928.         if (0 < `textScrollList -query -numberOfItems $list`) {
  929.             textScrollList -edit -removeAll $list;
  930.         }
  931.  
  932.         $runTimeCommands = `runTimeCommand -query -commandArray`;
  933.         for ($index = 0; $index < size($runTimeCommands); $index++) {
  934.             $category = `runTimeCommand -query -category $runTimeCommands[$index]`;
  935.             if ($selectedCategory[0] == $category) {
  936.                 textScrollList -edit -append $runTimeCommands[$index] $list;
  937.             }
  938.         }
  939.     }
  940.     
  941.     if ("" == $command) {
  942.         //
  943.         //    Select the first command.
  944.         //
  945.         if (0 < `textScrollList -query -numberOfItems $list`) {
  946.             textScrollList -edit -selectIndexedItem 1 $list;
  947.         }
  948.  
  949.     } else {
  950.         //
  951.         //    Select the specified command.
  952.         //
  953.         textScrollList -edit -selectItem $command $list;
  954.     }
  955.  
  956.     updateCurrentHotkeys();
  957.     updateCommandInfo();
  958.     updateCommandButtons();
  959.  
  960.     waitCursor -state off;
  961. }
  962.  
  963. proc updateCategoryPopupMenu()
  964. //
  965. //    Description:
  966. //        Fill in the category popup menu with all the categories.
  967. //
  968. {
  969.     string $categories[] = `textScrollList -query -allItems 
  970.         HotkeyEditorCategoryTextScrollList`;
  971.     int $index, $numberOfCategories = size($categories);
  972.  
  973.     popupMenu -edit -deleteAllItems HotkeyEditorCategoryPopupMenu;
  974.  
  975.     setParent -menu HotkeyEditorCategoryPopupMenu;
  976.  
  977.     for ($index = 0; $index < $numberOfCategories; $index++) {
  978.         menuItem -label $categories[$index]
  979.             -enableCommandRepeat false
  980.             -command ("hotkeyEditorCategoryPopupMenuSelect \"" +
  981.                 $categories[$index] + "\"");
  982.     }
  983. }
  984.  
  985. proc updateKeyPopupMenu()
  986. //
  987. //    Description:
  988. //        Fill in the key popup menu with all the special keys.
  989. //
  990. {
  991.     string $keys[];
  992.     int $index, $numberOfKeys;
  993.     string $keys1[] = {"Up", "Down", "Left", "Right", 
  994.             "Page_Up", "Page_Down", "Home","End",
  995.             "Return", "Space",
  996.             "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", 
  997.             "F9", "F10", "F11", "F12" };
  998.  
  999.     string $keys2[] = {"Up", "Down", "Left", "Right", 
  1000.             "Page_Up", "Page_Down", "Home", "End", "Insert",
  1001.             "Return", "Space",
  1002.             "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", 
  1003.             "F9", "F10", "F11", "F12" };
  1004.     if (`about -mac`)
  1005.     {
  1006.         $numberOfKeys = size($keys1);
  1007.         for($index = 0; $index < $numberOfKeys; $index++)
  1008.         {
  1009.             $keys[$index] = $keys1[$index];
  1010.         }
  1011.     }
  1012.     else
  1013.     {
  1014.         $numberOfKeys = size($keys2);
  1015.         for($index = 0; $index < $numberOfKeys; $index++)
  1016.         {
  1017.             $keys[$index] = $keys2[$index];
  1018.         }
  1019.     }
  1020.  
  1021.      $numberOfKeys = size($keys);
  1022.  
  1023.     popupMenu -edit -deleteAllItems HotkeyEditorKeyPopupMenu;
  1024.  
  1025.     setParent -menu HotkeyEditorKeyPopupMenu;
  1026.  
  1027.     for ($index = 0; $index < $numberOfKeys; $index++) {
  1028.         menuItem -label $keys[$index] -enableCommandRepeat false
  1029.             -command ("hotkeyEditorKeyPopupMenuSelect " + $keys[$index]);
  1030.  
  1031.         //    Throw in some separator items.
  1032.         //
  1033.         if (`about -mac`)
  1034.         {
  1035.             if ("Right" == $keys[$index] || "Home" == $keys[$index] ||
  1036.                 "Space" == $keys[$index]) 
  1037.             {
  1038.                 menuItem -divider true;
  1039.             }
  1040.         }
  1041.         else
  1042.         {
  1043.             if ("Right" == $keys[$index] || "Insert" == $keys[$index] ||
  1044.                 "Space" == $keys[$index]) 
  1045.             {
  1046.                 menuItem -divider true;
  1047.             }
  1048.         }
  1049.     }
  1050. }
  1051.  
  1052. proc removeHotkey(string $hotkey)
  1053. //
  1054. //    Description:
  1055. //        Remove a hotkey assignment.
  1056. //
  1057. //    Notes:
  1058. //        This procedure may be called as a result of deleting a runTimeCommand
  1059. //        that is attached to a custom Marking Menu (via the Marking Menu 
  1060. //        Editor).  The Hotkey Editor may or may not exist in this case.
  1061. //        Therefore DO NOT attempt to update any Hotkey Editor UI within this
  1062. //        function.  It is the responsibility of the calling function to
  1063. //        handle any required updating.
  1064. //        
  1065. {
  1066.     //    Convert the hotkey string into its parameter elements.
  1067.     //
  1068.     //    A hotkey string may look something like the following:
  1069.     //
  1070.     //    a
  1071.     //    Ctrl+z
  1072.     //    Alt+N Release
  1073.     //    Ctrl+Alt+b
  1074.     //    Ctrl+Alt+b Release
  1075.     // In case of MAC
  1076.     //    a
  1077.     //    Ctrl+z
  1078.     //
  1079.     //    From this string determine the 3 integer values that will
  1080.     //    reflect the Ctrl and Alt modifier state and the key 
  1081.     //    direction (ie. press or release).  We also want a string
  1082.     //    that contains only the key value.
  1083.     //
  1084.     //    First, break down the string into tokens.  Tokens are
  1085.     //    separated by white space.
  1086.     //
  1087.     string $token[], $plusString;
  1088.     int $numberOfTokens, $lastNumber, $lastButNum ;
  1089.     if(size($hotkey) > 1){
  1090.         $lastNumber = size($hotkey);
  1091.         $lastButNum = size($hotkey)-1;
  1092.         $plusString = `substring $hotkey $lastButNum $lastNumber`;
  1093.     }
  1094.  
  1095.     if($plusString == "++" ){
  1096.         $numberOfTokens = `tokenize $hotkey " +" $token`;
  1097.         $token[$numberOfTokens++] = "+";
  1098.     }else{
  1099.         if($hotkey == "+"){
  1100.             $numberOfTokens = 1;
  1101.             $token[0] = $hotkey;
  1102.         }else{
  1103.             $numberOfTokens = `tokenize $hotkey " +" $token`;
  1104.         }
  1105.     }
  1106.     
  1107.     string $key;
  1108.     int $ctrl = 0, $alt = 0, $press = 1, $cmd = 0;
  1109.  
  1110.     if (`about -mac`)
  1111.     {
  1112.         if (1 == $numberOfTokens) {
  1113.             //
  1114.             //    Only one token.  String contains the key only.
  1115.             //    Both modifiers are off and the key direction is 
  1116.             //    press.
  1117.             //
  1118.             $key = $token[0];
  1119.  
  1120.         } else if (2 == $numberOfTokens) {
  1121.             //
  1122.             //    Two tokens.  String is either a key release or
  1123.             //    a key with a single modifier.
  1124.             //
  1125.             if ("Release" == $token[1]) {
  1126.                 //
  1127.                 //    Key release.
  1128.                 //
  1129.                 $key = $token[0];
  1130.                 $press = 0;
  1131.  
  1132.             } else {
  1133.                 //
  1134.                 //    Key and single modifier.
  1135.                 //
  1136.                 $key = $token[1];
  1137.                 if ("control" == $token[0]) $ctrl = 1;
  1138.                 else if("option" == $token[0]) $alt = 1;
  1139.                 else $cmd = 1;
  1140.             }
  1141.  
  1142.         } else if (3 == $numberOfTokens) {
  1143.             //
  1144.             //    Three tokens.  String is either a key release with
  1145.             //    a single modifier or a key with both modifiers.
  1146.             //
  1147.             if ("Release" == $token[2]) {
  1148.                 //
  1149.                 //    Key release with single modifier.
  1150.                 //
  1151.                 $key = $token[1];
  1152.                 $press = 0;
  1153.                 if ("control" == $token[0]) $ctrl = 1;
  1154.                 else if("option" == $token[0]) $alt = 1;
  1155.                 else $cmd = 1;
  1156.  
  1157.             } else {
  1158.                 //
  1159.                 //    Key press with both modifiers.
  1160.                 //
  1161.                 $key = $token[2];
  1162.                 if((("control" == $token[0]) && ("option" == $token[1])) || (("control" == $token[1]) && ("option" == $token[0]))){
  1163.                     $ctrl = 1;
  1164.                     $alt = 1;
  1165.                 }else if ((("control" == $token[0]) && ("command" == $token[1])) || (("control" == $token[1]) && ("command" == $token[0])) ){
  1166.                     $ctrl = 1;
  1167.                     $cmd = 1;
  1168.                 }else{
  1169.                     $alt = 1;
  1170.                     $cmd = 1;
  1171.                 }
  1172.             }
  1173.  
  1174.         } else if (4 == $numberOfTokens){
  1175.             if ("Release" == $token[3]) {
  1176.                 //
  1177.                 //    Key release with single modifier.
  1178.                 //
  1179.                 $key = $token[2];
  1180.                 $press = 0;
  1181.                 if((("control" == $token[0]) && ("option" == $token[1])) || (("control" == $token[1]) && ("option" == $token[0]))){
  1182.                     $ctrl = 1;
  1183.                     $alt = 1;
  1184.                 }else if ((("control" == $token[0]) && ("command" == $token[1])) || (("control" == $token[1]) && ("command" == $token[0])) ){
  1185.                     $ctrl = 1;
  1186.                     $cmd = 1;
  1187.                 }else{
  1188.                     $alt = 1;
  1189.                     $cmd = 1;
  1190.                 }
  1191.  
  1192.             } else {
  1193.                 //
  1194.                 //    Key press with both modifiers.
  1195.                 //
  1196.                 $key = $token[3];
  1197.                 if((("control" == $token[0]) && ("option" == $token[1]) && ("command" != $token[2])) || 
  1198.                     (("control" == $token[1]) && ("option" == $token[0]) && ("command" != $token[2])) ||
  1199.                     (("control" == $token[1]) && ("option" == $token[2]) && ("command" != $token[0])) || 
  1200.                     (("control" == $token[2]) && ("option" == $token[1]) && ("command" != $token[0])) ){
  1201.                     $ctrl = 1;
  1202.                     $alt = 1;
  1203.                 }else if ( (("control" == $token[0]) && ("command" == $token[1]) && ("option" != $token[2])) || 
  1204.                             (("control" == $token[1]) && ("command" == $token[0]) && ("option" != $token[2])) ||
  1205.                             (("control" == $token[1]) && ("command" == $token[2]) && ("option" != $token[0])) || 
  1206.                             (("control" == $token[2]) && ("command" == $token[1]) && ("option" != $token[0])) ){
  1207.                     $ctrl = 1;
  1208.                     $cmd = 1;
  1209.                 }else if ( (("option" == $token[0]) && ("command" == $token[1]) && ("control" != $token[2])) || 
  1210.                             (("option" == $token[1]) && ("command" == $token[0]) && ("control" != $token[2])) ||
  1211.                             (("option" == $token[1]) && ("command" == $token[2]) && ("control" != $token[0])) || 
  1212.                             (("option" == $token[2]) && ("command" == $token[1]) && ("control" != $token[0])) ) {
  1213.                     $alt = 1;
  1214.                     $cmd = 1;
  1215.                 }else{
  1216.                     $alt = 1;
  1217.                     $cmd = 1;
  1218.                     $ctrl = 1;
  1219.                 }
  1220.             }
  1221.         }else{
  1222.             //
  1223.             //    All four tokens.  String is key release with both
  1224.             //    modifiers.
  1225.             //
  1226.             $ctrl = 1;
  1227.             $alt = 1;
  1228.             $cmd = 1;
  1229.             $key = $token[3];
  1230.             $press = 0;
  1231.         }
  1232.     }
  1233.     else{
  1234.         if (1 == $numberOfTokens) {
  1235.             //
  1236.             //    Only one token.  String contains the key only.
  1237.             //    Both modifiers are off and the key direction is 
  1238.             //    press.
  1239.             //
  1240.             $key = $token[0];
  1241.  
  1242.         } else if (2 == $numberOfTokens) {
  1243.             //
  1244.             //    Two tokens.  String is either a key release or
  1245.             //    a key with a single modifier.
  1246.             //
  1247.             if ("Release" == $token[1]) {
  1248.                 //
  1249.                 //    Key release.
  1250.                 //
  1251.                 $key = $token[0];
  1252.                 $press = 0;
  1253.  
  1254.             } else {
  1255.                 //
  1256.                 //    Key and single modifier.
  1257.                 //
  1258.                 $key = $token[1];
  1259.                 if ("Ctrl" == $token[0]) $ctrl = 1;
  1260.                 else $alt = 1;
  1261.             }
  1262.  
  1263.         } else if (3 == $numberOfTokens) {
  1264.             //
  1265.             //    Three tokens.  String is either a key release with
  1266.             //    a single modifier or a key with both modifiers.
  1267.             //
  1268.             if ("Release" == $token[2]) {
  1269.                 //
  1270.                 //    Key release with single modifier.
  1271.                 //
  1272.                 $key = $token[1];
  1273.                 $press = 0;
  1274.                 if ("Ctrl" == $token[0]) $ctrl = 1;
  1275.                 else $alt = 1;
  1276.  
  1277.             } else {
  1278.                 //
  1279.                 //    Key press with both modifiers.
  1280.                 //
  1281.                 $key = $token[2];
  1282.                 $ctrl = 1;
  1283.                 $alt = 1;
  1284.             }
  1285.  
  1286.         } else {
  1287.             //
  1288.             //    All four tokens.  String is key release with both
  1289.             //    modifiers.
  1290.             //
  1291.             $ctrl = 1;
  1292.             $alt = 1;
  1293.             $key = $token[2];
  1294.             $press = 0;
  1295.         }
  1296.     }
  1297.  
  1298.     //    To remove a hotkey assignment simply set the hotkey command flag
  1299.     //    -name or -releaseName to an empty string.
  1300.     //
  1301.     string $hotkeyCmd;
  1302.     $hotkeyCmd = constructHotkeyCommand($key, $ctrl, $alt, $cmd, $press, false, "");
  1303.     eval ($hotkeyCmd);
  1304. }
  1305.  
  1306. proc deleteRunTimeCommand(string $command)
  1307. //
  1308. //    Description:
  1309. //        Delete the given runTimeCommand.  Also cleanup, remove, and/or
  1310. //        delete any nameCommands and hotkeys that use this runTimeCommand.
  1311. //
  1312. //    Notes:
  1313. //        This procedure may be called as a result of deleting a runTimeCommand
  1314. //        that is attached to a custom Marking Menu (via the Marking Menu 
  1315. //        Editor).  The Hotkey Editor may or may not exist in this case.
  1316. //        Therefore DO NOT attempt to update any Hotkey Editor UI within this
  1317. //        function.  It is the responsibility of the calling function to
  1318. //        handle any required updating.
  1319. //        
  1320. {
  1321.     if (`runTimeCommand -exists $command` &&
  1322.         !`runTimeCommand -query -default $command`) {
  1323.  
  1324.         int $mustUpdateCurrentHotkeys = false;
  1325.  
  1326.         //
  1327.         //    Determine all the hotkeys pointing to this command.
  1328.         //
  1329.         string $hotkeys[] = getAllHotkeys($command);
  1330.  
  1331.         if (size($hotkeys) > 0) {
  1332.             for ($hotkey in $hotkeys) {
  1333.                 removeHotkey($hotkey);
  1334.             }
  1335.         }
  1336.  
  1337.         //    Determine the nameCommand associated with this command.
  1338.         //
  1339.         string $nameCommand = $command + "NameCommand";
  1340.         int $numberOfNameCommands = `assignCommand -query -numElements`;
  1341.         for ($index = 1; $index <= $numberOfNameCommands; $index++) {
  1342.             if ($nameCommand == `assignCommand -query -name $index`) {
  1343.                 assignCommand -edit -delete $index;
  1344.                 break;
  1345.             }
  1346.         }
  1347.  
  1348.         //    Now delete the command.
  1349.         //
  1350.         runTimeCommand -edit -delete $command;
  1351.     }
  1352. }
  1353.  
  1354. proc createCommandListArea(string $parent)
  1355. //
  1356. //    Description:
  1357. //        Create the UI for the category list and command list.
  1358. //
  1359. {
  1360.     setParent $parent;
  1361.  
  1362.     //    Category list.
  1363.     //
  1364.     string $categoryFrame = `frameLayout -label "Categories"
  1365.         -borderVisible false`;
  1366.     string $categoryForm = `formLayout`;
  1367.     string $categoryList = `textScrollList 
  1368.         -selectCommand ("hotkeyEditorCategoryTextScrollListSelect")
  1369.         HotkeyEditorCategoryTextScrollList`;
  1370.     setParent ..;
  1371.     setParent ..;
  1372.  
  1373.     //    Command list.
  1374.     //
  1375.     string $commandFrame = `frameLayout -label "Commands"
  1376.         -borderVisible false`;
  1377.     string $commandForm = `formLayout`;
  1378.     string $commandList = `textScrollList 
  1379.         -selectCommand ("hotkeyEditorCommandTextScrollListSelect")
  1380.         HotkeyEditorCommandTextScrollList`;
  1381.     setParent ..;
  1382.     setParent ..;
  1383.  
  1384.     //    Get all the categories.
  1385.     //
  1386.     string $categories[] = `runTimeCommand -query -categoryArray`;
  1387.     int $index, $numberOfCategories = size($categories);
  1388.  
  1389.     int $foundUserCategory = false;
  1390.  
  1391.     for ($index = 0; $index < $numberOfCategories; $index++) {
  1392.         textScrollList -edit -append $categories[$index] $categoryList;
  1393.         if ("User" == $categories[$index]) {
  1394.             $foundUserCategory = true;
  1395.         }
  1396.     }
  1397.  
  1398.     //    Create a default User category.
  1399.     //
  1400.     if (!$foundUserCategory) {
  1401.         textScrollList -edit -append "User" $categoryList;
  1402.     }
  1403.  
  1404.     //    Are there any runTimeCommands that don't have a category specified?
  1405.     //
  1406.     //    Eventually, there shouldn't be but until they all get one list them
  1407.     //    in the "Uncategorized" category.
  1408.     //
  1409.     string $runTimeCommands[] = `runTimeCommand -query -commandArray`;
  1410.     for ($index = 0; $index < size($runTimeCommands); $index++) {
  1411.         if ("" == `runTimeCommand -query -category $runTimeCommands[$index]`) {
  1412.             textScrollList -edit -append "Uncategorized" $categoryList;
  1413.             break;
  1414.         }
  1415.     }
  1416.  
  1417.     if (0 < `textScrollList -query -numberOfItems $categoryList`) {
  1418.         textScrollList -edit -selectIndexedItem 1 $categoryList;
  1419.     }
  1420.  
  1421.     formLayout -edit
  1422.         -attachForm     $categoryList "top"    0
  1423.         -attachForm     $categoryList "left"   0
  1424.         -attachForm     $categoryList "bottom" 0
  1425.         -attachForm     $categoryList "right"  0
  1426.         $categoryForm;
  1427.  
  1428.     formLayout -edit
  1429.         -attachForm     $commandList "top"    0
  1430.         -attachForm     $commandList "left"   0
  1431.         -attachForm     $commandList "bottom" 0
  1432.         -attachForm     $commandList "right"  0
  1433.         $commandForm;
  1434.  
  1435.     formLayout -edit
  1436.         -attachForm     $categoryFrame "top"    0
  1437.         -attachForm     $categoryFrame "left"   0
  1438.         -attachForm     $categoryFrame "bottom" 0
  1439.         -attachNone     $categoryFrame "right"
  1440.         -attachForm     $commandFrame  "top"    0 
  1441.         -attachControl  $commandFrame  "left"   5 $categoryFrame
  1442.         -attachForm     $commandFrame  "bottom" 0
  1443.         -attachForm     $commandFrame  "right"  0
  1444.         $parent;
  1445. }
  1446.  
  1447. proc createCommandInfoArea(string $parent)
  1448. //
  1449. //    Description:
  1450. //        Create the UI for listing all the information pertaining to
  1451. //        the current runTimeCommand.
  1452. //
  1453. {
  1454.     setParent $parent;
  1455.  
  1456.     //    All the buttons.
  1457.     //
  1458.     string $buttonForm = `columnLayout -adjustableColumn true`;
  1459.     string $createButton = `button -label "New" 
  1460.         -recomputeSize false -width 100
  1461.         -command ("hotkeyEditorCreateCommand")
  1462.         HotkeyEditorCreateCommandButton`;
  1463.     string $editButton = `button -label "Edit" 
  1464.         -command ("hotkeyEditorEditCommand")
  1465.         HotkeyEditorEditCommandButton`;
  1466.     string $deleteButton = `button -label "Delete"
  1467.         -command ("hotkeyEditorDeleteCommand")
  1468.         HotkeyEditorDeleteCommandButton`;
  1469.     separator -style "none" -height 10;
  1470.     string $acceptButton = `button -label "Accept"
  1471.         -command ("hotkeyEditorAcceptCommand")
  1472.         HotkeyEditorAcceptCommandButton`;
  1473.     string $cancelButton = `button -label "Cancel"
  1474.         -command ("hotkeyEditorCancelCommand")
  1475.         HotkeyEditorCancelCommandButton`;
  1476.     separator -style "none" -height 10;
  1477.     string $searchButton = `button -label "Search..."
  1478.         -command ("hotkeyEditorSearchForRunTimeCommand")
  1479.         HotkeyEditorSearchButton`;
  1480.     string $helpButton = `button -label "Help..."
  1481.         -command ("showHelp HotkeyEditor")
  1482.         HotkeyEditorHelpButton`;
  1483.  
  1484.     //    The labels and fields.
  1485.     //
  1486.     setParent $parent;
  1487.     string $info = `columnLayout -adjustableColumn true`;
  1488.     rowLayout
  1489.         -numberOfColumns 2
  1490.         -adjustableColumn 2
  1491.         -columnAlign 1 "right"
  1492.         -columnWidth 1 80 
  1493.         -columnWidth 2 300
  1494.         -columnAttach 1 "both" 5
  1495.         -columnAttach 2 "both" 0;
  1496.     text -label "Name";
  1497.     textField -editable false HotkeyEditorNameField;
  1498.     setParent ..;
  1499.  
  1500.     rowLayout
  1501.         -numberOfColumns 2
  1502.         -adjustableColumn 2
  1503.         -columnAlign 1 "right"
  1504.         -columnWidth 1 80 
  1505.         -columnWidth 2 300
  1506.         -columnAttach 1 "both" 5
  1507.         -columnAttach 2 "both" 0;
  1508.     text -label "Description";
  1509.     textField -editable false HotkeyEditorDescriptionField;
  1510.     setParent ..;
  1511.  
  1512.     rowLayout
  1513.         -numberOfColumns 3
  1514.         -columnAlign 1 "right"
  1515.         -columnWidth 1 80 
  1516.         -columnWidth 2 200
  1517.         -columnAttach 1 "both" 5
  1518.         -columnAttach 2 "both" 0;
  1519.     text -label "Category"; 
  1520.     textField -editable false HotkeyEditorCategoryField;
  1521.     iconTextButton -image1 "popupMenuIcon.xpm" -height 26 -width 18
  1522.         HotkeyEditorCategoryPopupMenuButton;
  1523.     popupMenu -button 1 HotkeyEditorCategoryPopupMenu;
  1524.     setParent ..;
  1525.  
  1526.     rowLayout
  1527.         -numberOfColumns 2
  1528.         -adjustableColumn 2
  1529.         -columnAlign 1 "right"
  1530.         -columnWidth 1 80 
  1531.         -columnWidth 2 300
  1532.         -columnAttach 1 "both" 5
  1533.         -columnAttach 2 "both" 0;
  1534.     text -label "Command";
  1535.     scrollField -height 160 -editable false 
  1536.         HotkeyEditorCommandField;
  1537.     setParent ..;
  1538.  
  1539.     formLayout -edit
  1540.         -numberOfDivisions 100
  1541.         -attachForm     $info       "top"    0
  1542.         -attachForm     $info       "left"   0
  1543.         -attachForm     $info       "bottom" 0
  1544.         -attachControl  $info       "right"  5 $buttonForm
  1545.         -attachForm     $buttonForm "top"    0
  1546.         -attachNone     $buttonForm "left"
  1547.         -attachForm     $buttonForm "bottom" 0
  1548.         -attachForm     $buttonForm "right"  0
  1549.         $parent;
  1550. }
  1551.  
  1552. proc createCurrentHotkeyArea(string $parent)
  1553. //
  1554. //    Description:
  1555. //        Create the UI for listing the hotkeys assigned to the
  1556. //        current command.
  1557. //
  1558. {
  1559.     setParent $parent;
  1560.  
  1561.     string $hotkeyFrame = `frameLayout -label "Current Hotkeys"
  1562.         -borderVisible false`;
  1563.     string $hotkeyForm = `formLayout`;
  1564.  
  1565.     string $list = `textScrollList -numberOfRows 3
  1566.         -selectCommand ("hotkeyEditorHotkeyTextScrollListSelect")
  1567.         HotkeyEditorHotkeyTextScrollList`;
  1568.  
  1569.     // set the textScrollList height so that, the scroll bar 
  1570.     // shows the scrollBox when there are enough contents to scroll
  1571.     //
  1572.     if(`about -mac`) {
  1573.         textScrollList -e -h 100 HotkeyEditorHotkeyTextScrollList;
  1574.     }
  1575.  
  1576.     string $removeButton = `button -label "Remove"
  1577.         -command ("hotkeyEditorRemoveHotkey")
  1578.         HotkeyEditorRemoveHotkeyButton`;
  1579.  
  1580.     string $restoreButton = `button -label "Restore Defaults"
  1581.         -command ("hotkeyEditorRestoreDefaultHotkeys")
  1582.         HotkeyEditorRestoreDefaultHotkeysButton`;
  1583.  
  1584.     string $listAllButton = `button -label "List All..."
  1585.         -command ("hotkeyEditorListAllHotkeys")
  1586.         HotkeyEditorListAllHotkeysButton`;
  1587.  
  1588.     formLayout -edit
  1589.         -attachForm     $list          "top"    0
  1590.         -attachForm     $list          "left"   0
  1591.         -attachNone     $list          "bottom"
  1592.         -attachForm     $list          "right"  0
  1593.  
  1594.         -attachControl  $removeButton  "top"    5 $list
  1595.         -attachForm     $removeButton  "left"   5
  1596.         -attachNone     $removeButton  "bottom"
  1597.         -attachForm     $removeButton  "right"  5
  1598.  
  1599.         -attachControl  $listAllButton "top"    5 $removeButton
  1600.         -attachForm     $listAllButton "left"   5
  1601.         -attachNone     $listAllButton "bottom"
  1602.         -attachPosition $listAllButton "right"  2 50
  1603.  
  1604.         -attachControl  $restoreButton "top"    5 $removeButton
  1605.         -attachPosition $restoreButton "left"   2 50
  1606.         -attachNone     $restoreButton "bottom"
  1607.         -attachForm     $restoreButton "right"  5
  1608.  
  1609.         $hotkeyForm;
  1610.  
  1611.     formLayout -edit
  1612.         -attachForm    $hotkeyFrame  "top"    0
  1613.         -attachForm    $hotkeyFrame  "left"   0
  1614.         -attachForm    $hotkeyFrame  "bottom" 0
  1615.         -attachForm    $hotkeyFrame  "right"  0
  1616.         $parent;
  1617. }
  1618.  
  1619. proc createNewHotkeyArea(string $parent)
  1620. //
  1621. //    Description:
  1622. //        Create the UI for assigning new hotkeys.
  1623. //
  1624. {
  1625.     setParent $parent;
  1626.  
  1627.     frameLayout -label "Assign New Hotkey" -labelAlign "center" 
  1628.         -borderStyle "etchedIn" -marginWidth 5 -marginHeight 5;
  1629.  
  1630.     columnLayout -adjustableColumn true;
  1631.  
  1632.     //    Key field and popup menu.
  1633.     //
  1634.     if(`about -macOS`){
  1635. /*
  1636.         rowColumnLayout -numberOfColumns 4 
  1637.         -columnWidth 1 70
  1638.         -columnWidth 2  60
  1639.         -columnWidth 3 60
  1640.         -columnWidth 4 60
  1641.         -columnAlign 1 "right"
  1642.         -columnAlign 2 "left"
  1643.         -columnAlign 3 "left"
  1644.         -columnAlign 4 "left"
  1645.         -columnAttach 4 "left" 0;
  1646. */        
  1647.         rowColumnLayout -numberOfColumns 4 
  1648.         -columnWidth 1 70
  1649.         -columnWidth 2  70
  1650.         -columnWidth 3 70
  1651.         -columnWidth 4 60
  1652.         -columnAlign 1 "right"
  1653.         -columnAlign 2 "left"
  1654.         -columnAlign 3 "left"
  1655.         -columnAlign 4 "left"
  1656.         -columnAttach 4 "left" 0;
  1657.         
  1658.     }else{
  1659.         rowColumnLayout -numberOfColumns 3 
  1660.             -columnWidth 1 70
  1661.             -columnWidth 2 80
  1662.             -columnWidth 3 80
  1663.             -columnAlign 1 "right"
  1664.             -columnAlign 2 "left"
  1665.             -columnAlign 3 "left"
  1666.             -columnAttach 3 "left" 0;
  1667.     }
  1668.  
  1669.     text -label "Key" HotkeyEditorKeyLabel; 
  1670.     textField -changeCommand ("hotkeyEditorHotkeyKeyFieldChange")
  1671.         HotkeyEditorKeyField;
  1672.         iconTextButton -image1 "popupMenuIcon.xpm" -height 26 -width 18
  1673.             HotkeyEditorKeyPopupMenuButton;
  1674.     popupMenu -button 1 HotkeyEditorKeyPopupMenu;
  1675.     if(`about -macOS`){
  1676.         text -label "";
  1677.     }
  1678.     //    Modifier check boxes.
  1679.     //
  1680.     text -label "Modifier" HotkeyEditorModifierLabel;
  1681.     if (`about -macOS`) {
  1682.         checkBox -label "control" -changeCommand ("hotkeyEditorHotkeyCtrlCheckBoxChange") 
  1683.             HotkeyEditorCtrlCheckBox;
  1684.     }
  1685.     else {
  1686.         checkBox -label "Ctrl" -changeCommand ("hotkeyEditorHotkeyCtrlCheckBoxChange") 
  1687.             HotkeyEditorCtrlCheckBox;
  1688.     }
  1689.     if(`about -macOS`){
  1690.         checkBox -label "option" -changeCommand ("hotkeyEditorHotkeyAltCheckBoxChange") 
  1691.         HotkeyEditorAltCheckBox;
  1692.     }else{
  1693.         checkBox -label "Alt" -changeCommand ("hotkeyEditorHotkeyAltCheckBoxChange") 
  1694.         HotkeyEditorAltCheckBox;
  1695.     }
  1696.     if(`about -macOS`) {
  1697.         checkBox -label "command" -changeCommand ("hotkeyEditorHotkeyCmdCheckBoxChange") 
  1698.             HotkeyEditorCmdCheckBox;
  1699.     }
  1700.  
  1701.     //    Key press vs. release radio buttons.
  1702.     //
  1703.     text -label "Direction" HotkeyEditorDirectionLabel;
  1704.     radioCollection;
  1705.     radioButton -label "Press" -select
  1706.         -changeCommand ("hotkeyEditorHotkeyPressRadioButtonChange") 
  1707.         HotkeyEditorPressRadioButton;
  1708.     radioButton -label "Release" 
  1709.         -changeCommand ("hotkeyEditorHotkeyReleaseRadioButtonChange")
  1710.         HotkeyEditorReleaseRadioButton;
  1711.  
  1712.     setParent ..;
  1713.  
  1714.     separator -height 5 -style "none";
  1715.  
  1716.     //    Repeatable check box.
  1717.     //
  1718.     rowColumnLayout -numberOfColumns 2 
  1719.         -columnWidth 1 15
  1720.         -columnWidth 2 200
  1721.         -columnAlign 1 "right"
  1722.         -columnAlign 2 "left";
  1723.     text -label " " HotkeyEditorRepeatableLabel;
  1724.     checkBox -label "Add to Recent Command List" 
  1725.         -align "left" HotkeyEditorRepeatableCheckBox;
  1726.     setParent ..;
  1727.  
  1728.  
  1729.     //    Text for query results.
  1730.     //
  1731.     text -align "left" -recomputeSize false -label "" -height 47
  1732.         HotkeyEditorQueryResultText;
  1733.  
  1734.     //    The buttons.
  1735.     //
  1736.     string $buttons = `formLayout`;
  1737.     string $assign = `button -label "Assign" 
  1738.         -command ("hotkeyEditorAssignHotkey")
  1739.         HotkeyEditorAssignHotkeyButton`;
  1740.     string $query = `button -label "Query" 
  1741.         -command ("hotkeyEditorQueryHotkey")
  1742.         HotkeyEditorQueryHotkeyButton`;
  1743.     string $find = `button -label "Find" 
  1744.         -command ("hotkeyEditorFindHotkey")
  1745.         HotkeyEditorFindHotkeyButton`;
  1746.     setParent ..;
  1747.  
  1748.     formLayout -edit
  1749.         -numberOfDivisions 100
  1750.         -attachForm     $assign "top"    0
  1751.         -attachForm     $assign "left"   0
  1752.         -attachForm     $assign "bottom" 0
  1753.         -attachPosition $assign "right"  2 33
  1754.         -attachForm     $query  "top"    0
  1755.         -attachPosition $query  "left"   2 33
  1756.         -attachForm     $query  "bottom" 0
  1757.         -attachPosition $query  "right"  2 66
  1758.         -attachForm     $find   "top"    0
  1759.         -attachPosition $find   "left"   2 66
  1760.         -attachForm     $find   "bottom" 0
  1761.         -attachForm     $find   "right"  0
  1762.         $buttons;
  1763. }
  1764.  
  1765. proc createButtonsArea(string $parent)
  1766. //
  1767. //    Description:
  1768. //        Create the buttons for the window.
  1769. //
  1770. {
  1771.     setParent $parent;
  1772.  
  1773.     string $saveButton = `button -label "Save" 
  1774.         -command ("hotkeyEditorSave")
  1775.         HotkeyEditorSaveButton`;
  1776.     string $closeButton = `button -label "Close" 
  1777.         -command ("hotkeyEditorClose")
  1778.         HotkeyEditorCloseButton`;
  1779.  
  1780.     formLayout -edit
  1781.         -numberOfDivisions 100
  1782.         -attachForm     $saveButton  "top"    0
  1783.         -attachForm     $saveButton  "left"   0
  1784.         -attachForm     $saveButton  "bottom" 0
  1785.         -attachPosition $saveButton  "right"  2 50
  1786.         -attachForm     $closeButton "top"    0
  1787.         -attachPosition $closeButton "left"   2 50
  1788.         -attachForm     $closeButton "bottom" 0
  1789.         -attachForm     $closeButton "right"  0
  1790.         $parent;
  1791. }
  1792.  
  1793. proc resetCreateOrEditMode()
  1794. //
  1795. //    Description:
  1796. //        Reset the edit mode.
  1797. //
  1798. {
  1799.     global int $gHotkeyEditorInCreateMode;
  1800.     global int $gHotkeyEditorInEditMode;
  1801.  
  1802.     $gHotkeyEditorInCreateMode = false;
  1803.     $gHotkeyEditorInEditMode = false;
  1804.  
  1805.     updateCommandInfo();
  1806.     updateCommandButtons();
  1807.     enableNewHotkeyArea(true);
  1808. }
  1809.  
  1810. global proc string[] getAllValidKeys()
  1811. //
  1812. //    Description:
  1813. //        Return a string array containing all the valid keys
  1814. //        that a hotkey may be assigned to.
  1815. //
  1816. {
  1817.     int $index, $numberOfKeys;
  1818.     string $hotkeys[];
  1819.     string $hotkeys1[] = {
  1820.         "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
  1821.         "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
  1822.         "u", "v", "w", "x", "y", "z",
  1823.  
  1824.         "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
  1825.         "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
  1826.         "U", "V", "W", "X", "Y", "Z",
  1827.         
  1828.         "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
  1829.         ")", "!", "@", "#", "$", "%", "^", "&", "*", "(",
  1830.         
  1831.         "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", 
  1832.         "F9", "F10", "F11", "F12",
  1833.         
  1834.         "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/",
  1835.         "~", "_", "+", "{", "}", "|", ":", "\"", "<", ">", "?",
  1836.  
  1837.         "Up", "Down", "Left", "Right",
  1838.  
  1839.         "Page_Up", "Page_Down", "Home", "End",
  1840.         "Return", "Space"
  1841.     };
  1842.     string $hotkeys2[] = {
  1843.         "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
  1844.         "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
  1845.         "u", "v", "w", "x", "y", "z",
  1846.  
  1847.         "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
  1848.         "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
  1849.         "U", "V", "W", "X", "Y", "Z",
  1850.         
  1851.         "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
  1852.         ")", "!", "@", "#", "$", "%", "^", "&", "*", "(",
  1853.         
  1854.         "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", 
  1855.         "F9", "F10", "F11", "F12",
  1856.         
  1857.         "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/",
  1858.         "~", "_", "+", "{", "}", "|", ":", "\"", "<", ">", "?",
  1859.  
  1860.         "Up", "Down", "Left", "Right",
  1861.  
  1862.         "Page_Up", "Page_Down", "Home", "End", "Insert",
  1863.         "Return", "Space"
  1864.     };
  1865.     if (`about -mac`)
  1866.     {
  1867.          $numberOfKeys = size($hotkeys1);
  1868.         for($index = 0; $index < $numberOfKeys; $index++)
  1869.         {
  1870.             $hotkeys[$index] = $hotkeys1[$index];
  1871.         }
  1872.     }
  1873.     else
  1874.     {
  1875.         
  1876.         $numberOfKeys = size($hotkeys2);
  1877.         for($index = 0; $index < $numberOfKeys; $index++)
  1878.         {
  1879.             $hotkeys[$index] = $hotkeys2[$index];
  1880.         }
  1881.     }
  1882.     
  1883.     return $hotkeys;
  1884. }
  1885.  
  1886. global proc string getHotkeyCommandNew (
  1887.     string $key,
  1888.     int    $ctrl,
  1889.     int    $alt,
  1890.     int    $command,
  1891.     int    $press)
  1892. //
  1893. //    Description:
  1894. //        Return the command that will be executed if the specified hotkey
  1895. //        is invoked.
  1896. //
  1897. //    Arguments:
  1898. //        key        - The key.
  1899. //        ctrl    - State of the Ctrl modifier.
  1900. //        alt        - State of the Alt modifier.
  1901. //        press    - Key direction.  Specify true for key press, false for 
  1902. //                  key release.
  1903. //
  1904. //    Returns:
  1905. //        A string containing the command that will be executed.  An empty
  1906. //        string is returned if no command is attached to the hotkey.
  1907. //
  1908. //    Examples:
  1909. //        //    Determine the press command attached to the hotkey Ctrl a.
  1910. //        //
  1911. //        string $press = getHotkeyCommand("a", true, false, true);
  1912. //
  1913. //        //    Determine the release command attached to the hotkey Alt Z.
  1914. //        //
  1915. //        string $release = getHotkeyCommand("Z", false, true, false);
  1916. //
  1917. {
  1918.     string $result = "";
  1919.     string $nameCommand = "";
  1920.  
  1921.     string $hotkeyQueryCommand = "hotkey -query ";
  1922.     if ($ctrl) $hotkeyQueryCommand += "-ctl ";
  1923.     if ($alt) $hotkeyQueryCommand += "-alt ";
  1924.     if($command) $hotkeyQueryCommand += "-cmd ";
  1925.     if ($press) $hotkeyQueryCommand += "-name ";
  1926.     else $hotkeyQueryCommand += "-releaseName ";
  1927.  
  1928.     if ("\"" == $key || "\\" == $key) {
  1929.         //
  1930.         //    Need to preceed double quote and backslash characters
  1931.         //    with a backslash.
  1932.         //
  1933.         $hotkeyQueryCommand += ("\"\\" + $key + "\"");
  1934.  
  1935.     } else if ("-" == $key) {
  1936.         //
  1937.         //    Can't pass a dash as a string argument to a command
  1938.         //    because it gets interpreted as the beginning of another
  1939.         //    flag.  Use the word "Dash" instead.
  1940.         //
  1941.         $hotkeyQueryCommand += ("Dash");
  1942.  
  1943.     } else {
  1944.         //
  1945.         //    Surround the string argument with quotes so that 
  1946.         //    non-alphabetic characters get treated as strings
  1947.         //    properly.
  1948.         //
  1949.         $hotkeyQueryCommand += ("\"" + $key + "\"");
  1950.     }
  1951.     $nameCommand = eval($hotkeyQueryCommand);
  1952.  
  1953.     if ("" != $nameCommand) {
  1954.         //
  1955.         //    Get the runTimeCommand this nameCommand points to.
  1956.         //
  1957.         string $runTimeCommand = getRunTimeCommandFromNameCommand($nameCommand);
  1958.         if ("" != $runTimeCommand) {
  1959.             $result = $runTimeCommand;
  1960.             
  1961.         } else {
  1962.             //
  1963.             //    This is a name command that hasn't been converted to use
  1964.             //    a runTimeCommand yet.
  1965.             //
  1966.             $result = $nameCommand;
  1967.         }
  1968.     }
  1969.     
  1970.     return $result;
  1971. }
  1972.  
  1973. global proc string getHotkeyCommand(
  1974.     string $key,
  1975.     int    $ctrl,
  1976.     int    $alt,
  1977.     int       $cmd,
  1978.     int    $press)
  1979. {
  1980.     if(`about -mac`){
  1981.         return  (getHotkeyCommandNew ($key, $ctrl, $alt,  $cmd, $press));
  1982.     }
  1983.  
  1984.     return  (getHotkeyCommandNew ($key, $ctrl, $alt,  false, $press));
  1985. }
  1986.  
  1987. global proc string getRunTimeCommandFromNameCommand(string $nameCommand)
  1988. //
  1989. //    Description:
  1990. //        Return the runTimeCommand that is invoked by the specified 
  1991. //        nameCommand.
  1992. //
  1993. {
  1994.     string $result = "";
  1995.     int $index, $numberOfNameCommands;
  1996.  
  1997.     $numberOfNameCommands = `assignCommand -query -numElements`;
  1998.     for ($index = 1; $index <= $numberOfNameCommands; $index++) {
  1999.         if ($nameCommand == `assignCommand -query -name $index`) {
  2000.             $result = `assignCommand -query -command $index`;
  2001.             break;
  2002.         }
  2003.     }
  2004.     
  2005.     if (!`runTimeCommand -exists $result`) $result = "";
  2006.     
  2007.     return $result;
  2008. }
  2009.  
  2010. global proc hotkeyEditorCategoryTextScrollListSelect()
  2011. //
  2012. //    Description:
  2013. //        This procedure is called whenever the user selects a category
  2014. //        in the list.
  2015. //
  2016. {
  2017.     resetCreateOrEditMode();
  2018.     updateCommandTextScrollList("");
  2019. }
  2020.  
  2021. global proc hotkeyEditorCommandTextScrollListSelect()
  2022. //
  2023. //    Description:
  2024. //        This procedure is called whenever the user selects a command
  2025. //        in the list.
  2026. //
  2027. {
  2028.     resetCreateOrEditMode();
  2029.     updateCurrentHotkeys();
  2030.     updateCommandButtons();
  2031.     updateCommandInfo();
  2032. }
  2033.  
  2034. global proc hotkeyEditorHotkeyKeyFieldChange()
  2035. //
  2036. //    Description:
  2037. //        This procedure is called whenever the user changes the value
  2038. //        in the key field.
  2039. //
  2040. {
  2041.     if (!updateQueryHotkeyText()) {
  2042.         setQueryHotkeyText("");
  2043.     }
  2044. }
  2045.  
  2046. global proc hotkeyEditorHotkeyCtrlCheckBoxChange()
  2047. //
  2048. //    Description:
  2049. //        This procedure is called whenever the user turns on or
  2050. //        off the Ctrl check box.
  2051. //
  2052. {
  2053.     if (!updateQueryHotkeyText()) {
  2054.         setQueryHotkeyText("");
  2055.     }
  2056. }
  2057.  
  2058. global proc hotkeyEditorHotkeyAltCheckBoxChange()
  2059. //
  2060. //    Description:
  2061. //        This procedure is called whenever the user turns on or
  2062. //        off the Alt check box.
  2063. //
  2064. {
  2065.     if (!updateQueryHotkeyText()) {
  2066.         setQueryHotkeyText("");
  2067.     }
  2068. }
  2069.  
  2070. global proc hotkeyEditorHotkeyCmdCheckBoxChange()
  2071. //
  2072. //    Description:
  2073. //        This procedure is called whenever the user turns on or
  2074. //        off the Alt check box.
  2075. //
  2076. {
  2077.     if (!updateQueryHotkeyText()) {
  2078.         setQueryHotkeyText("");
  2079.     }
  2080. }
  2081.  
  2082.  
  2083. global proc hotkeyEditorHotkeyPressRadioButtonChange()
  2084. //
  2085. //    Description:
  2086. //        This procedure is called whenever the user turns on or
  2087. //        off the Press radio button.
  2088. //
  2089. {
  2090.     if (!updateQueryHotkeyText()) {
  2091.         setQueryHotkeyText("");
  2092.     }
  2093. }
  2094.  
  2095. global proc hotkeyEditorHotkeyReleaseRadioButtonChange()
  2096. //
  2097. //    Description:
  2098. //        This procedure is called whenever the user turns on or
  2099. //        off the Release radio button.
  2100. //
  2101. {
  2102.     if (!updateQueryHotkeyText()) {
  2103.         setQueryHotkeyText("");
  2104.     }
  2105. }
  2106.  
  2107. global proc hotkeyEditorHotkeyTextScrollListSelect()
  2108. //
  2109. //    Description:
  2110. //        This procedure is called whenever the user selects a hotkey
  2111. //        in the list.
  2112. //
  2113. {
  2114.     resetCreateOrEditMode();
  2115.     updateRemoveHotkeyButton();
  2116. }
  2117.  
  2118. global proc hotkeyEditorCategoryPopupMenuSelect(string $category)
  2119. //
  2120. //    Description:
  2121. //        This procedure is called whenever the user selects a category
  2122. //        from the popup menu.
  2123. //
  2124. {
  2125.     textField -edit -text $category HotkeyEditorCategoryField;
  2126. }
  2127.  
  2128. global proc hotkeyEditorKeyPopupMenuSelect(string $key)
  2129. //
  2130. //    Description:
  2131. //        This procedure is called whenever the user selects a key
  2132. //        from the popup menu.
  2133. //
  2134. {
  2135.     textField -edit -text $key HotkeyEditorKeyField;
  2136.     hotkeyEditorQueryHotkey();
  2137. }
  2138.  
  2139. global proc hotkeyEditorCreateCommand()
  2140. //
  2141. //    Description:
  2142. //        This procedure is called whenever the user presses the
  2143. //        Create command button.
  2144. //
  2145. {
  2146.     global int $gHotkeyEditorInCreateMode;
  2147.  
  2148.     $gHotkeyEditorInCreateMode = true;
  2149.  
  2150.     updateCommandInfo();
  2151.     updateCommandButtons();
  2152.     enableNewHotkeyArea(false);
  2153. }
  2154.  
  2155. global proc hotkeyEditorEditCommand()
  2156. //
  2157. //    Description:
  2158. //        This procedure is called whenever the user presses the
  2159. //        Edit command button.
  2160. //
  2161. {
  2162.     global int $gHotkeyEditorInEditMode;
  2163.  
  2164.     $gHotkeyEditorInEditMode = true;
  2165.  
  2166.     updateCommandInfo();
  2167.     updateCommandButtons();
  2168.     enableNewHotkeyArea(false);
  2169. }
  2170.  
  2171. global proc hotkeyEditorDeleteCommand()
  2172. //
  2173. //    Description:
  2174. //        This procedure is called whenever the user presses the
  2175. //        Delete command button.
  2176. //
  2177. {
  2178.     string $command = getCurrentRunTimeCommand();
  2179.     string $list = "HotkeyEditorCommandTextScrollList";
  2180.  
  2181.     //
  2182.     //    Remove the item from the list.
  2183.     //
  2184.     if ("" != $command) {
  2185.  
  2186.         //    Confirm that the user really wants to delete the command.
  2187.         //
  2188.         //    Fixes bug #126567.
  2189.         //
  2190.         string $message = "Delete the " + $command + " command?";
  2191.         $confirmResponse = `confirmDialog -button "Delete" -button "Cancel"
  2192.             -defaultButton "Delete" -cancelButton "Cancel"
  2193.             -message $message`;
  2194.  
  2195.         //
  2196.         //    *** Return statement ***
  2197.         //
  2198.         if ("Delete" != $confirmResponse) return;
  2199.  
  2200.         deleteRunTimeCommand($command);
  2201.         textScrollList -edit -removeItem $command $list;
  2202.  
  2203.         //    Select the first command in the list.
  2204.         //
  2205.         int $numberOfItems = `textScrollList -query -numberOfItems $list`;
  2206.         if ($numberOfItems > 0) {
  2207.             textScrollList -edit -selectIndexedItem 1 $list;
  2208.             textScrollList -edit -showIndexedItem 1 $list;
  2209.         }
  2210.  
  2211.         updateCommandInfo();
  2212.         updateCommandButtons();
  2213.         updateCurrentHotkeys();
  2214.     }
  2215. }
  2216.  
  2217. global proc hotkeyEditorAcceptCommand()
  2218. //
  2219. //    Description:
  2220. //        This procedure is called whenever the user presses the
  2221. //        Accept command button.
  2222. //
  2223. {
  2224.     global int $gHotkeyEditorInCreateMode;
  2225.     global int $gHotkeyEditorInEditMode;
  2226.  
  2227.     string $oldName, $name, $description, $command, $list;
  2228.     string $oldCategory, $category;
  2229.     string $runTimeCommand, $errorMessage;
  2230.     int $numberOfItems, $numberOfLines, $showItem;
  2231.  
  2232.     $oldName = getCurrentRunTimeCommand();
  2233.     $oldCategory = getCurrentCategory();
  2234.     $name = `textField -query -text HotkeyEditorNameField`;
  2235.     $description = `textField -query -text HotkeyEditorDescriptionField`;
  2236.     $command = `scrollField -query -text HotkeyEditorCommandField`;
  2237.     $category = `textField -query -text HotkeyEditorCategoryField`;
  2238.     $runTimeCommand = ("runTimeCommand " + $name);
  2239.     $list = "HotkeyEditorCommandTextScrollList";
  2240.  
  2241.     //    Fix for bug #132763. Allowing the user to have a run time command execute
  2242.     //    itself will result in an infinite loop when the command is called.
  2243.     //
  2244.     if ($name == $command) {
  2245.         confirmDialog -button "Close" -defaultButton "Close" -cancelButton "Close"
  2246.             -message "The name must not be the same as the command.";
  2247.         return;
  2248.     }
  2249.  
  2250.     if ($gHotkeyEditorInEditMode) {
  2251.         
  2252.         //    Is the category name valid?
  2253.         //
  2254.         if ($category != $oldCategory && !isValidCategory($category)) {
  2255.             $errorMessage = "Select a category from the popup menu or enter"
  2256.                 + " a value that begins with a character\nand is followed by"
  2257.                 + " alphanumeric characters, underscores, or spaces.";
  2258.         }
  2259.  
  2260.         if ("" == $errorMessage && $name != $oldName) {
  2261.             //
  2262.             //    We can't really rename commands so we have to create a new
  2263.             //    command with the given name and then delete the old one.
  2264.             //
  2265.             if ("" != $name && isValidName($name) && isUniqueName($name)) {
  2266.  
  2267.                 eval ($runTimeCommand);
  2268.                 runTimeCommand -edit -delete $oldName;
  2269.                 
  2270.                 //    Determine the old item's position in the list.
  2271.                 //
  2272.                 string $items[] = `textScrollList -query -allItems $list`;
  2273.                 int $index, $count = size($items);
  2274.                 for ($index = 0; $index < $count; $index++) {
  2275.                     if ($oldName == $items[$index]) {
  2276.                         break;
  2277.                     }
  2278.                 }
  2279.  
  2280.                 if ($category == $oldCategory) {
  2281.  
  2282.                     //    Add our new item after the old item.
  2283.                     //
  2284.                     textScrollList -edit -appendPosition ($index + 1) $name $list;
  2285.  
  2286.                     //    Remove the old item from the list.
  2287.                     //
  2288.                     textScrollList -edit -removeItem $oldName $list;
  2289.                 }
  2290.  
  2291.             } else if (!isValidName($name)) {
  2292.                 //
  2293.                 //    Not a valid name.
  2294.                 //
  2295.                 $errorMessage = "The name must begin with an alphabetic"
  2296.                     + " character or underscore.  The remaining\ncharacters"
  2297.                     + " must consist of alphanumeric characters or underscores.";
  2298.  
  2299.             } else if (!isUniqueName($name)) {
  2300.                 $errorMessage = getNameErrorMessage($name);
  2301.             }
  2302.         }
  2303.  
  2304.         if ("" == $errorMessage) {
  2305.             runTimeCommand -edit 
  2306.                 -command $command
  2307.                 -annotation $description
  2308.                 -category $category
  2309.                 $name;
  2310.         }
  2311.  
  2312.     } else {
  2313.         //
  2314.         //    Validate the field values.
  2315.         //
  2316.         if ("" != $name && isValidName($name) && isUniqueName($name) 
  2317.             && isValidCategory($category)) {
  2318.  
  2319.             eval ($runTimeCommand);
  2320.  
  2321.             runTimeCommand -edit
  2322.                 -command $command 
  2323.                 -annotation $description 
  2324.                 -category $category 
  2325.                 $name;
  2326.  
  2327.             if ($category == $oldCategory) {
  2328.                 
  2329.                 //    Add our item to the list.
  2330.                 //
  2331.                 textScrollList -edit -append $name -selectItem $name $list;
  2332.  
  2333.                 //    Make our newly added item visible within the list.
  2334.                 //
  2335.                 $numberOfItems = `textScrollList -query -numberOfItems $list`;
  2336.                 $numberOfLines = `textScrollList -query -numberOfRows $list`;
  2337.                 $showItem = $numberOfItems - $numberOfLines + 1;
  2338.                 if ($showItem < 1) $showItem = 1;
  2339.                 textScrollList -edit -showIndexedItem $showItem $list;
  2340.             }
  2341.  
  2342.         } else if (!isValidName($name)) {
  2343.             //
  2344.             //    Not a valid name.
  2345.             //
  2346.             $errorMessage = "The name must begin with an alphabetic"
  2347.                 + " character or underscore.  The remaining\ncharacters"
  2348.                 + " must consist of alphanumeric characters or underscores.";
  2349.  
  2350.         } else if (!isUniqueName($name)) {
  2351.             $errorMessage = getNameErrorMessage($name);
  2352.  
  2353.         } else if (!isValidCategory($category)) {
  2354.             $errorMessage = "Select a category from the popup menu or enter"
  2355.                 + " a value that begins with a character\nand is followed by"
  2356.                 + " alphanumeric characters, underscores, or spaces.";
  2357.         }
  2358.     } 
  2359.  
  2360.     if ("" == $errorMessage) {
  2361.         $gHotkeyEditorInCreateMode = false;
  2362.         $gHotkeyEditorInEditMode = false;
  2363.  
  2364.         $list = "HotkeyEditorCategoryTextScrollList";
  2365.  
  2366.         if (!isExistingCategory($category)) {
  2367.             //
  2368.             //    Add the category to the list.
  2369.             //
  2370.             textScrollList -edit -append $category -selectItem $category $list;
  2371.         }
  2372.  
  2373.         if ($category != $oldCategory) {
  2374.             //
  2375.             //    Select the new category.
  2376.             //
  2377.             textScrollList -edit -selectItem $category $list;
  2378.             
  2379.             //    Now update the command list.
  2380.             //
  2381.             updateCommandTextScrollList($name);
  2382.         }
  2383.  
  2384.         updateCommandInfo();
  2385.         updateCommandButtons();
  2386.         updateCurrentHotkeys();
  2387.         enableNewHotkeyArea(true);
  2388.  
  2389.     } else {
  2390.         confirmDialog -button "Close" -message $errorMessage
  2391.             -defaultButton "Close" -cancelButton "Close";
  2392.     }
  2393. }
  2394.  
  2395. global proc hotkeyEditorCancelCommand()
  2396. //
  2397. //    Description:
  2398. //        This procedure is called whenever the user presses the
  2399. //        Cancel command button.
  2400. //
  2401. {
  2402.     resetCreateOrEditMode();
  2403. }
  2404.  
  2405. global proc hotkeyEditorSearchForRunTimeCommand()
  2406. //
  2407. //    Description:
  2408. //        This procedure is called whenever the user presses the
  2409. //        Search button.
  2410. //
  2411. {
  2412.     searchForRunTimeCommandWindow;
  2413. }
  2414.  
  2415. global proc hotkeyEditorAssignHotkey()
  2416. //
  2417. //    Description:
  2418. //        This procedure is called whenever the user presses the
  2419. //        Assign hotkey button.
  2420. //
  2421. {
  2422.     int        $cmd = 0;
  2423.  
  2424.     string $key = `textField -query -text HotkeyEditorKeyField`;
  2425.     int $ctrl = `checkBox -query -value HotkeyEditorCtrlCheckBox`;
  2426.     int $alt = `checkBox -query -value HotkeyEditorAltCheckBox`;
  2427.     int $press = `radioButton -query -select HotkeyEditorPressRadioButton`;
  2428.     int $repeat = `checkBox -query -value HotkeyEditorRepeatableCheckBox`;
  2429.  
  2430.     if(`about -macOS`){
  2431.         $cmd = `checkBox -query -value HotkeyEditorCmdCheckBox`;
  2432.     }
  2433.     string $runTimeCommand, $nameCommandName;
  2434.     int $nameCommandIndex;
  2435.     int $setUpReleaseHotkey = false;
  2436.  
  2437.     if ("" == $key || !isValidKey($key)) {
  2438.         $label = "You must enter a valid key\nin the Key field above.";
  2439.         text -edit -label $label HotkeyEditorQueryResultText;
  2440.  
  2441.     } else {
  2442.         string $existingCommand = getHotkeyCommand($key, $ctrl, $alt, $cmd, $press);
  2443.         string $confirmResponse;
  2444.  
  2445.         if ("" != $existingCommand) {
  2446.  
  2447.             string $message = "The hotkey is already assigned to " + $existingCommand
  2448.                 + ".\nDo you want to override this with your new hotkey assignment?";
  2449.             $confirmResponse = `confirmDialog -button "Assign" -button "Cancel"    
  2450.                 -defaultButton "Assign" -cancelButton "Cancel"
  2451.                 -message $message`;
  2452.  
  2453.             //
  2454.             //    *** Return statement ***
  2455.             //
  2456.             if ("Assign" != $confirmResponse) return;
  2457.         }
  2458.  
  2459.         //    Check for dangling release hotkeys that could cause trouble for
  2460.         //    the user.  Bug #88549 and #137784.
  2461.         //
  2462.         //    If the user assigns a press hotkey then check to see if there
  2463.         //    was a release command attached to the same hotkey.  The user
  2464.         //    would not expect that their new command be executed on press
  2465.         //    and their old release command be executed on release.
  2466.         //
  2467.         if ($press) {
  2468.             //
  2469.             //    Check if there is a release command attached to the hotkey
  2470.             //    as well.
  2471.             //
  2472.             $releaseCommand = getHotkeyCommand($key, $ctrl, $alt, $cmd, 0);
  2473.  
  2474.             if ("" != $releaseCommand) {
  2475.                 $message = "The hotkey also has a release command assigned to " +
  2476.                     $releaseCommand + ".\nThis assignment will be removed.";
  2477.                 confirmDialog -button "OK" -defaultButton "OK" -cancelButton "OK" 
  2478.                     -message $message;
  2479.                 $removeReleaseHotkeyCmd = constructHotkeyCommand(
  2480.                     $key, $ctrl, $alt, $cmd, 0, 0, "");
  2481.                 eval ($removeReleaseHotkeyCmd);
  2482.             }
  2483.         }
  2484.  
  2485.         $runTimeCommand = getCurrentRunTimeCommand();
  2486.         $nameCommandName = $runTimeCommand + "NameCommand";
  2487.         $nameCommandIndex = getNameCommand($nameCommandName);
  2488.  
  2489.         //    Have we created a nameCommand object for this runTimeCommand
  2490.         //    yet?  If we have it will be have the same name as the runTimeCommand
  2491.         //    with "NameCommand" appended to it.  For example, a runTimeCommand
  2492.         //    called "Example" will have a nameCommand object called 
  2493.         //    "ExampleNameCommand".
  2494.         //
  2495.         //    Note that a runTimeCommand may have other default nameCommand
  2496.         //    objects pointing to it (ie. set up in nameCommandSetup.mel).
  2497.         //    We don't want to apply the hotkey to one of these.
  2498.         //
  2499.  
  2500.         if (0 == $nameCommandIndex) {
  2501.             //
  2502.             //    Create a new nameCommand object.
  2503.             //
  2504.             //    Note that nameCommand command requires the annotation flag to
  2505.             //    be set.  Simply set it to the name of the command so that it's
  2506.             //    unique.
  2507.             //
  2508.             string $nameCommandCmd = "nameCommand -ann \"" + $nameCommandName 
  2509.                 + "\" -command (\"" + $runTimeCommand + "\") " 
  2510.                 + $nameCommandName;
  2511.             eval ($nameCommandCmd);
  2512.             $nameCommandIndex = getNameCommand($nameCommandName);
  2513.         }
  2514.  
  2515.         //    Are we trying to attach the hotkey to a user Marking Menu?
  2516.         //
  2517.         //    We can determine this by querying the Category flag of the
  2518.         //    runTimeCommand.  All runTimeCommands that post custom
  2519.         //    Marking Menus will have the category set to 
  2520.         //    "User Marking Menus".
  2521.         //
  2522.         if ("User Marking Menus" 
  2523.             == `runTimeCommand -query -category $runTimeCommand`) {
  2524.  
  2525.             //
  2526.             //    Why do we need to know if the runTimeCommand is for
  2527.             //    showing a user marking menu?  Because we must
  2528.             //    ensure that the command that actually shows the
  2529.             //    marking menu includes the hotkey modifiers.
  2530.             //
  2531.             //    The problem is that the user creates their marking
  2532.             //    menu in the Marking Menu Editor.  At that time we
  2533.             //    have no idea what hotkey and modifiers the user is
  2534.             //    going to attach.
  2535.             //    
  2536.             //    But now we know their hotkey assignment and simply
  2537.             //    need to update the command accordingly.
  2538.             //
  2539.             string $modifiers, $command, $newCommand;
  2540.             string $buffer[], $tokens[];
  2541.             int $index, $tokenCount;
  2542.             
  2543.             $command = `runTimeCommand -query -command $runTimeCommand`;
  2544.  
  2545.             //    Determine if the command is for popping up the marking
  2546.             //    menu or for popping it down.
  2547.             //
  2548.             //    We don't have to modify the pop down command, only
  2549.             //    the popup command.
  2550.             //
  2551.             //    The pop up command is assumed to consist of three lines
  2552.             //    separated by new lines, eg "\n".
  2553.             //
  2554.             $tokenCount = `tokenize $command "\n" $buffer`;
  2555.             if (3 == $tokenCount) {
  2556.                 //
  2557.                 //    This is the marking menu pop up command.
  2558.                 //
  2559.  
  2560.                 //    Start constructing the new command that will include
  2561.                 //    the appropriate hotkey modifiers.
  2562.                 //
  2563.                 //    Add the first line of the command.
  2564.                 //
  2565.                 $newCommand = $buffer[0] + "\n";
  2566.  
  2567.                 //    Tokenize the second line so we can find the 
  2568.                 //    -ctl, -alt, and -cmd flags and set their correct
  2569.                 //    values.
  2570.                 //
  2571.                 $tokenCount = `tokenize $buffer[1] " " $tokens`;
  2572.  
  2573.                 int $altFound = false, $cmdFound = false;
  2574.  
  2575.                 for ($index = 0; $index < $tokenCount; $index++) {
  2576.  
  2577.                     if ("-ctl" == $tokens[$index]) {
  2578.                         $newCommand += $tokens[$index] + " ";
  2579.                         if ($ctrl) {
  2580.                             $newCommand += "true ";
  2581.                         } else {
  2582.                             $newCommand += "false ";
  2583.                         }
  2584.                         $index++;
  2585.  
  2586.                     } else if ("-alt" == $tokens[$index]) {
  2587.                         $newCommand += $tokens[$index] + " ";
  2588.                         if ($alt) {
  2589.                             $newCommand += "true ";
  2590.                         } else {
  2591.                             $newCommand += "false ";
  2592.                         }
  2593.                         $altFound = true;
  2594.                         $index++;
  2595.  
  2596.                     }else if ("-cmd" == $tokens[$index]) {
  2597.                         $newCommand += $tokens[$index] + " ";
  2598.                         if ($cmd) {
  2599.                             $newCommand += "true ";
  2600.                         } else {
  2601.                             $newCommand += "false ";
  2602.                         }
  2603.                         $cmdFound = true;
  2604.                         $index++;
  2605.  
  2606.                     } else if ("-allowOptionBoxes" == $tokens[$index]) {
  2607.                         //
  2608.                         //    The Marking Menu editor didn't use to set the
  2609.                         //    -alt flag.  If we've detected the 
  2610.                         //    -allowOptionBoxes flag and the -alt flag
  2611.                         //    hasn't been found then insert it as well as
  2612.                         //    its value.
  2613.                         //
  2614.                         //    Then include the -allowOptionBoxes flag.
  2615.                         //
  2616.                         if (!$altFound && !$cmdFound) {
  2617.                             $newCommand += "-alt ";
  2618.                             if ($alt) {
  2619.                                 $newCommand += "true ";
  2620.                             } else {
  2621.                                 $newCommand += "false ";
  2622.                             }
  2623.                         }
  2624.                         $newCommand += $tokens[$index] + " ";
  2625.  
  2626.                     } else {
  2627.                         //
  2628.                         //    Include all the other parts of the command.
  2629.                         //
  2630.                         $newCommand += $tokens[$index] + " ";
  2631.                     }
  2632.                 }
  2633.                 
  2634.                 //    Don't forget to add the last line of the original
  2635.                 //    command.
  2636.                 //
  2637.                 $newCommand += "\n" + $buffer[2] + "\n";
  2638.  
  2639.                 //    Attach the new command to the runTimeCommand.
  2640.                 //
  2641.                 runTimeCommand -edit -command $newCommand $runTimeCommand;
  2642.  
  2643.                 //    Update the command info area to reflect the change in
  2644.                 //    the runTimeCommand's command.
  2645.                 //
  2646.                 updateCommandInfo();
  2647.             }
  2648.  
  2649.             if ($press) {
  2650.                 //
  2651.                 //    It would be nice to automatically attach the release
  2652.                 //    hotkey for the user's marking menu.
  2653.                 //
  2654.                 string $message = "Your marking menu will not work correctly " +
  2655.                     "unless you also attach the release hotkey.\nDo you want this " +
  2656.                     "to be set up for you?";
  2657.                 $confirmResponse = `confirmDialog -button "Yes" -button "No"    
  2658.                     -defaultButton "Yes" -cancelButton "No"
  2659.                     -message $message`;
  2660.  
  2661.                 if ("Yes" == $confirmResponse) $setUpReleaseHotkey = true;
  2662.             }
  2663.         }
  2664.  
  2665.         string $hotkeyCmd = constructHotkeyCommand(
  2666.             $key, $ctrl, $alt, $cmd, $press, $repeat, $nameCommandName);
  2667.         eval ($hotkeyCmd);
  2668.  
  2669.         updateCurrentHotkeys();
  2670.         updateQueryHotkeyText();
  2671.  
  2672.         //    Now reset the "Assign Hotkey" field and checkboxes.
  2673.         //
  2674.         //    Fixes bug #126569.
  2675.         //
  2676.         textField -edit -text "" HotkeyEditorKeyField;
  2677.         checkBox -edit -value false HotkeyEditorCtrlCheckBox;
  2678.         checkBox -edit -value false HotkeyEditorAltCheckBox;
  2679.     if(`about -macOS`){
  2680.             checkBox -edit -value false HotkeyEditorCmdCheckBox;
  2681.     }
  2682.         radioButton -edit -select HotkeyEditorPressRadioButton;
  2683.     }
  2684.  
  2685.     if ($setUpReleaseHotkey) {
  2686.         //
  2687.         //    The user has requested that we also attach the release hotkey
  2688.         //    for the marking menu.
  2689.         //
  2690.         //    Construct the name of the release runTimeCommand.  To do this,
  2691.         //    take the press runTimeCommand, strip off "_Press" and add
  2692.         //    "_Release".  These are the suffixes added 
  2693.         //    in hotkeyEditor_createMarkingMenu().
  2694.         //
  2695.         string $releaseName = substring($runTimeCommand, 1, (size($runTimeCommand) - 6));
  2696.         $runTimeCommand = $releaseName + "_Release";
  2697.         $nameCommandName = $runTimeCommand + "NameCommand";
  2698.         $nameCommandIndex = getNameCommand($nameCommandName);
  2699.  
  2700.         if (0 == $nameCommandIndex) {
  2701.             //
  2702.             //    Create a new nameCommand object.
  2703.             //
  2704.             //    Note that nameCommand command requires the annotation flag to
  2705.             //    be set.  Simply set it to the name of the command so that it's
  2706.             //    unique.
  2707.             //
  2708.             string $nameCommandCmd = "nameCommand -ann \"" + $nameCommandName 
  2709.                 + "\" -command (\"" + $runTimeCommand + "\") " 
  2710.                 + $nameCommandName;
  2711.             eval ($nameCommandCmd);
  2712.             $nameCommandIndex = getNameCommand($nameCommandName);
  2713.         }
  2714.  
  2715.         string $hotkeyCmd = constructHotkeyCommand(
  2716.             $key, $ctrl, $alt, $cmd, false, $repeat, $nameCommandName);
  2717.         eval ($hotkeyCmd);
  2718.     }
  2719. }
  2720.  
  2721. global proc hotkeyEditorQueryHotkey()
  2722. //
  2723. //    Description:
  2724. //        This procedure is called whenever the user presses the
  2725. //        Query hotkey button.
  2726. //
  2727. {
  2728.     if (!updateQueryHotkeyText()) {
  2729.         text -edit 
  2730.             -label "You must enter a valid key\nin the Key field above."
  2731.             HotkeyEditorQueryResultText;
  2732.     }
  2733. }
  2734.  
  2735. global proc hotkeyEditorFindHotkey()
  2736. //
  2737. //    Description:
  2738. //        This procedure is called whenever the user presses the
  2739. //        Find hotkey button.
  2740. //
  2741. //        The purpose of this procedure is to locate and select 
  2742. //        in the category/command scroll lists the command assigned 
  2743. //        to the current hotkey.
  2744. //
  2745. {
  2746.     int        $cmd = 0;
  2747.     string $key = `textField -query -text HotkeyEditorKeyField`;
  2748.     int $ctrl = `checkBox -query -value HotkeyEditorCtrlCheckBox`;
  2749.     int $alt = `checkBox -query -value HotkeyEditorAltCheckBox`;
  2750.     int $press = `radioButton -query -select HotkeyEditorPressRadioButton`;
  2751.  
  2752.     if(`about -macOS`){
  2753.         $cmd = `checkBox -query -value HotkeyEditorCmdCheckBox`;
  2754.     }
  2755.     if ("" == $key || !isValidKey($key)) {
  2756.         //
  2757.         //    Won't be able to find command attached to invalid key.
  2758.         //
  2759.         text -edit 
  2760.             -label "You must enter a valid key\nin the Key field above."
  2761.             HotkeyEditorQueryResultText;
  2762.  
  2763.     } else {
  2764.         string $command = getHotkeyCommand($key, $ctrl, $alt, $cmd, $press);
  2765.  
  2766.         if ("" == $command) {
  2767.             //
  2768.             //    No command assigned.
  2769.             //
  2770.             string $label = "\"";
  2771.             if ($ctrl) {
  2772.                 if(`about -macOS`)
  2773.                     $label += ("control+");
  2774.                 else
  2775.                     $label += ("Ctrl+");
  2776.                 
  2777.             }
  2778.             if ($alt) {
  2779.                 if(`about -macOS`)
  2780.                     $label += ("option+");
  2781.                 else
  2782.                     $label += ("Alt+");
  2783.             }
  2784.             if($cmd){
  2785.                 if(`about -macOS`)
  2786.                     $label += ("command+");
  2787.                 else
  2788.                     $label += ("Command+");
  2789.             }
  2790.             $label += $key;
  2791.  
  2792.             if (!$press) {
  2793.                 $label += " Release";
  2794.             }
  2795.             $label += "\" is assigned to:\n  Nothing";
  2796.  
  2797.             text -edit -label $label HotkeyEditorQueryResultText;
  2798.  
  2799.         } else {
  2800.             //
  2801.             //    Select the corresponding category and command in the
  2802.             //    scroll lists.
  2803.             //
  2804.             string $category = `runTimeCommand -query -category $command`;
  2805.             textScrollList -edit -selectItem $category 
  2806.                 HotkeyEditorCategoryTextScrollList;
  2807.             updateCommandTextScrollList($command);
  2808.         }
  2809.     }
  2810. }
  2811.  
  2812. global proc hotkeyEditorRemoveHotkey()
  2813. //
  2814. //    Description:
  2815. //        This procedure is called whenever the user presses the
  2816. //        Remove hotkey button.
  2817. //
  2818. {
  2819.     //    Get the selected hotkey item in the scroll list.
  2820.     //
  2821.     string $hotkey[] = `textScrollList -query 
  2822.         -selectItem HotkeyEditorHotkeyTextScrollList`;
  2823.  
  2824.     removeHotkey($hotkey[0]);
  2825.  
  2826.     updateCurrentHotkeys();
  2827. }
  2828.  
  2829. global proc hotkeyEditorRestoreDefaultHotkeys()
  2830. //
  2831. //    Description:
  2832. //        This procedure is called whenever the user presses the
  2833. //        Restore Defaults button.
  2834. //
  2835. //        Post a dialog confirming the user wants to restore the
  2836. //        default hotkeys and thus losing all their custom hotkey
  2837. //        assignments.
  2838. //
  2839. //        Then restore the default hotkeys.
  2840. //
  2841. {
  2842.     string $message, $response;
  2843.  
  2844.     $message = "All user defined hotkey assignments will be irretrievably " +
  2845.         "lost.\nContinue restoring default hotkey assignments?";
  2846.  
  2847.     $response = `confirmDialog -button "Yes" -button "Cancel"
  2848.         -defaultButton "Yes" -cancelButton "Cancel" -message $message`;
  2849.  
  2850.     if ($response == "Yes") {
  2851.         hotkey -factorySettings;
  2852.         updateCurrentHotkeys();
  2853.     }
  2854. }
  2855.  
  2856. global proc hotkeyEditorListAllHotkeys()
  2857. //
  2858. //    Description:
  2859. //        This procedure is called whenever the user presses the
  2860. //        List All hotkeys button.
  2861. //
  2862. {
  2863.     listHotkeysWindow;
  2864. }
  2865.  
  2866. global proc hotkeyEditorSave()
  2867. //
  2868. //    Description:
  2869. //        This procedure is called whenever the user presses the
  2870. //        Save button.
  2871. //
  2872. {
  2873.     savePrefs -hotkeys;
  2874. }
  2875.  
  2876. global proc hotkeyEditorClose()
  2877. //
  2878. //    Description:
  2879. //        This procedure is called whenever the user presses the
  2880. //        Close button.
  2881. //
  2882. {
  2883.     deleteUI -window HotkeyEditor;
  2884. }
  2885.  
  2886. //    ------------------------------------------------------------------
  2887. //
  2888. //    BEGIN: interface to the Marking Menu Editor, and related routines.
  2889. //
  2890. //    These procedures should only be called by the Marking Menu Editor. 
  2891. //
  2892. proc string hotkeyEditor_generatePressAnnotationForMM(string $annotation)
  2893. {
  2894.     return ($annotation + " (Press)");
  2895. }
  2896.  
  2897. proc string hotkeyEditor_generateReleaseAnnotationForMM(string $annotation)
  2898. {
  2899.     return ($annotation + " (Release)");
  2900. }
  2901.  
  2902. global proc int hotkeyEditor_createMarkingMenu(
  2903.     string $markingMenuName,
  2904.     string $pressCommandString,
  2905.     string $releaseCommandString) 
  2906. //
  2907. //    Description:
  2908. //        Create the runTimeCommands for a marking menu.
  2909. //
  2910. //        Returns false upon failure.
  2911. //
  2912. {
  2913.     //    Has a marking menu with the given marking menu name already 
  2914.     //    been created?
  2915.     //
  2916.     if (hotkeyEditor_doesMarkingMenuExist($markingMenuName)) {
  2917.         warning "A Marking Menu with this name already exists in the Hotkey Editor";
  2918.         return false;
  2919.     }
  2920.  
  2921.     //    Create a couple of runTimeCommands.  One for the press command and
  2922.     //    one for the release command.
  2923.     //
  2924.     //    Is the given marking menu name valid?  Ie. no spaces, punctuation, etc.?
  2925.     //
  2926.     string $popUpCommandName = $markingMenuName + "_Press";
  2927.     string $popDownCommandName = $markingMenuName + "_Release";
  2928.  
  2929.     string $pressAnnotation = hotkeyEditor_generatePressAnnotationForMM($markingMenuName);
  2930.     string $releaseAnnotation = hotkeyEditor_generateReleaseAnnotationForMM($markingMenuName);
  2931.  
  2932.     string $runTimeCommand;
  2933.  
  2934.     $runTimeCommand = ("runTimeCommand " + $popUpCommandName);
  2935.     eval ($runTimeCommand);
  2936.  
  2937.     runTimeCommand -edit
  2938.         -command    $pressCommandString
  2939.         -category   "User Marking Menus"
  2940.         -annotation $pressAnnotation
  2941.         $popUpCommandName;
  2942.  
  2943.     $runTimeCommand = ("runTimeCommand " + $popDownCommandName);
  2944.     eval ($runTimeCommand);
  2945.  
  2946.     runTimeCommand -edit
  2947.         -command    $releaseCommandString
  2948.         -category   "User Marking Menus"
  2949.         -annotation $releaseAnnotation
  2950.         $popDownCommandName;
  2951.  
  2952.     if (`window -exists HotkeyEditor`) {
  2953.         //
  2954.         //    If the Hotkey Editor is currently visible then update
  2955.         //    the window to reflect the presence of a new command.
  2956.         //
  2957.         if (!isExistingCategory("User Marking Menus")) {
  2958.             //
  2959.             //    Update the category popup menu so it includes the new
  2960.             //    category.
  2961.             //
  2962.             updateCategoryPopupMenu();
  2963.  
  2964.             //    Add the new category to the list of categories.
  2965.             //
  2966.             textScrollList -edit -append "User Marking Menus"
  2967.                 HotkeyEditorCommandTextScrollList;
  2968.         }
  2969.  
  2970.         //    Update the command list if necessary.
  2971.         //
  2972.         if ("User Marking Menus" == getCurrentCategory()) {
  2973.             updateCommandTextScrollList($popUpCommandName);
  2974.         }
  2975.     }
  2976.     return true;
  2977. }
  2978.  
  2979. global proc hotkeyEditor_deleteMarkingMenu(string $markingMenuName)
  2980. //
  2981. //    Description:
  2982. //        Delete the runTimeCommands for a marking menu.
  2983. //
  2984. {
  2985.     string $popUpCommandName = $markingMenuName + "_Press";
  2986.     string $popDownCommandName = $markingMenuName + "_Release";
  2987.  
  2988.     deleteRunTimeCommand($popUpCommandName);
  2989.     deleteRunTimeCommand($popDownCommandName);
  2990.  
  2991.     if (`window -exists HotkeyEditor`) {
  2992.         //
  2993.         //    If the Hotkey Editor is currently visible then update
  2994.         //    the window to reflect the removal of the commands.
  2995.         //
  2996.  
  2997.         //    Update the command list if necessary.
  2998.         //
  2999.         if ("User Marking Menus" == getCurrentCategory()) {
  3000.             updateCommandTextScrollList("");
  3001.         }
  3002.     }
  3003. }
  3004.  
  3005. global proc int hotkeyEditor_renameMarkingMenu(
  3006.     string $oldMarkingMenuName,
  3007.     string $newMarkingMenuName,
  3008.     string $newPressCommandString,
  3009.     string $newReleaseCommandString)
  3010. //
  3011. //    Description:
  3012. //        Rename the runTimeCommands associated with a marking menu.
  3013. //
  3014. {
  3015.     int $result = false;
  3016.  
  3017.     //    Not much to do if the name marking menu name hasn't changed.
  3018.     //
  3019.     if ($oldMarkingMenuName == $newMarkingMenuName) return true;
  3020.  
  3021.     //    Simply create new runTimeCommands based on the new name.
  3022.     //
  3023.     $result = hotkeyEditor_createMarkingMenu(
  3024.         $newMarkingMenuName,
  3025.         $newPressCommandString,
  3026.         $newReleaseCommandString);
  3027.  
  3028.     //    If successful in creating the new commands then delete the old
  3029.     //    commands.
  3030.     //
  3031.     if ($result) {
  3032.         string $oldPopUpCommandName = $oldMarkingMenuName + "_Press";
  3033.         string $oldPopDownCommandName = $oldMarkingMenuName + "_Release";
  3034.  
  3035.         deleteRunTimeCommand($oldPopUpCommandName);
  3036.         deleteRunTimeCommand($oldPopDownCommandName);
  3037.  
  3038.         if (`window -exists HotkeyEditor`) {
  3039.             //
  3040.             //    If the Hotkey Editor is currently visible then update
  3041.             //    the window to reflect the removal of the commands.
  3042.             //
  3043.  
  3044.             //    Update the command list if necessary.
  3045.             //
  3046.             if ("User Marking Menus" == getCurrentCategory()) {
  3047.                 updateCommandTextScrollList("");
  3048.             }
  3049.         }
  3050.     }
  3051.     return $result;
  3052. }
  3053.  
  3054. global proc int hotkeyEditor_doesMarkingMenuExist(string $markingMenuName)
  3055. //
  3056. //    Description:
  3057. //        Return true if a marking menu with the given name already
  3058. //        exists.
  3059. //
  3060. {
  3061.     int $result = true;
  3062.  
  3063.     string $popUpCommandName = $markingMenuName + "_Press";
  3064.     string $popDownCommandName = $markingMenuName + "_Release";
  3065.     
  3066.     if (!`runTimeCommand -exists $popUpCommandName` &&
  3067.         !`runTimeCommand -exists $popDownCommandName`) {
  3068.         $result = false;
  3069.     }
  3070.  
  3071.     return $result;
  3072. }
  3073. //
  3074. //    END: interface to the Marking Menu Editor, and related routines
  3075. //
  3076. //    ---------------------------------------------------------------
  3077.  
  3078. global proc hotkeyEditor()
  3079. //
  3080. //    Description:
  3081. //        Create the Hotkey Editor.
  3082. //
  3083. {
  3084.     //    If the window already exists then just show it and return.
  3085.     //
  3086.     if (`window -exists HotkeyEditor`) {
  3087.         showWindow HotkeyEditor;
  3088.         return;
  3089.     }
  3090.  
  3091.     //    Otherwise, build the window.
  3092.     //
  3093.     window -title "Hotkey Editor" -height 700 -width 700 HotkeyEditor;
  3094.     
  3095.     string $form = `formLayout`;
  3096.  
  3097.     string $commandListArea = `formLayout`;
  3098.     setParent ..;
  3099.     string $commandInfoArea = `formLayout`;
  3100.     setParent ..;
  3101.     string $hotkeyArea = `formLayout`;
  3102.     setParent ..;
  3103.     string $buttonsArea = `formLayout`;
  3104.     setParent ..;
  3105.  
  3106.     setParent $hotkeyArea;
  3107.     string $currentHotkeyArea = `formLayout`;
  3108.     setParent ..;
  3109.     string $newHotkeyArea = `formLayout`;
  3110.     setParent ..;
  3111.  
  3112.     createCommandListArea($commandListArea);
  3113.     createCommandInfoArea($commandInfoArea);
  3114.     createCurrentHotkeyArea($currentHotkeyArea);
  3115.     createNewHotkeyArea($newHotkeyArea);
  3116.     createButtonsArea($buttonsArea);
  3117.  
  3118.     formLayout -edit
  3119.         -attachForm    $currentHotkeyArea "top"    0
  3120.         -attachForm    $currentHotkeyArea "left"   0
  3121.         -attachNone    $currentHotkeyArea "bottom"
  3122.         -attachForm    $currentHotkeyArea "right"  0
  3123.         -attachControl $newHotkeyArea     "top"    20 $currentHotkeyArea
  3124.         -attachForm    $newHotkeyArea     "left"   0
  3125.         -attachNone    $newHotkeyArea     "bottom"
  3126.         -attachForm    $newHotkeyArea     "right"  0
  3127.         $hotkeyArea;
  3128.  
  3129.     formLayout -edit
  3130.         -attachForm    $commandListArea   "top"    5
  3131.         -attachForm    $commandListArea   "left"   5
  3132.         -attachControl $commandListArea   "bottom" 15 $commandInfoArea
  3133.         -attachControl $commandListArea   "right"  5 $hotkeyArea
  3134.         -attachForm    $hotkeyArea        "top"    5
  3135.         -attachNone    $hotkeyArea        "left"
  3136.         -attachControl $hotkeyArea        "bottom" 15 $commandInfoArea
  3137.         -attachForm    $hotkeyArea        "right"  5
  3138.         -attachNone    $commandInfoArea   "top"
  3139.         -attachForm    $commandInfoArea   "left"   5
  3140.         -attachControl $commandInfoArea   "bottom" 5 $buttonsArea
  3141.         -attachForm    $commandInfoArea   "right"  5
  3142.         -attachNone    $buttonsArea       "top"
  3143.         -attachForm    $buttonsArea       "left"   5
  3144.         -attachForm    $buttonsArea       "bottom" 5
  3145.         -attachForm    $buttonsArea       "right"  5
  3146.         $form;
  3147.  
  3148.     resetCreateOrEditMode();
  3149.     updateCommandTextScrollList("");
  3150.     updateCategoryPopupMenu();
  3151.     updateKeyPopupMenu();
  3152.  
  3153.     showWindow HotkeyEditor;
  3154. }
  3155.